mcp_schema_generator
基于注解的模型上下文协议(MCP)服务器代码生成器。通过自动生成功能消除样板代码
- 星标
- 0
- 复刻
- 0
- 最近推送(UTC)
- 2026年6月19日
- 项目状态
- 未归档
原始 README
以下为英文项目原文快照,最新内容请访问 GitHub。
mcp_schema_generator
Annotation-driven MCP server generation for Dart & Flutter.
Eliminates Model Context Protocol (MCP) boilerplate by generating tool registration, JSON schemas, parameter parsing, and error handling from simple Dart annotations.
Features
- Zero Boilerplate: Automatically map Dart methods to MCP Tools.
- JSON Schema Generation: Converts Dart types (
String,int,List,Enum, nullables) into strictly typed JSON schemas. - Built-in Validation: Specify boundaries with
@McpParam(minimum: 1). - Type Safety: The generated code provides strongly typed
ToolDefinitionmetadata maps.
Installation
Add the dependencies to your pubspec.yaml:
dependencies:
mcp_schema_annotations: ^1.0.0-beta.3
mcp_schema_runtime: ^1.0.0-beta.3
dev_dependencies:
mcp_schema_generator: ^1.0.0-beta.3
build_runner: ^2.15.0
Quick Start
- Annotate your server class and methods.
import 'package:mcp_schema_annotations/mcp_schema_annotations.dart';
import 'package:mcp_schema_runtime/mcp_schema_runtime.dart';
part 'server.g.dart'; // The generated file
@McpServer(name: 'analytics_server')
class AnalyticsServer {
@McpTool(description: 'Get user details')
Future<User> getUser(
@McpParam(description: 'User ID', minimum: 1) int id,
) async {
return User(id);
}
}
- Run the generator
dart run build_runner build
- Access the generated metadata!
final server = AnalyticsServer();
print(server.mcpTools); // List of generated ToolDefinitions!
print(server.mcpToolMap); // Map of tool names to ToolDefinitions!
Annotations
@McpServer(name: 'server_name'): Marks a class as an MCP server.@McpTool(name: 'toolName', description: '...'): Marks a method as an MCP Tool.@McpParam(description: '...', minimum: 0, maximum: 10, pattern: r'^[A-Z]$'): Provides additional JSON Schema metadata constraints for parameters.
Generated Output
The generator produces a Dart extension on your server class:
extension AnalyticsServerMcpExtension on AnalyticsServer {
List<ToolDefinition> get mcpTools => [
ToolDefinition(
name: 'getUser',
description: 'Get user details',
inputSchema: {
'type': 'object',
'properties': {
'id': {
'description': 'User ID',
'minimum': 1,
'type': 'integer',
}
},
'required': ['id']
}
)
];
Map<String, ToolDefinition> get mcpToolMap => { ... };
}
Supported Types
String->stringint->integerdouble/num->numberbool->booleanList<T>->arrayEnum->string(withenumlist)- Nullable types (e.g.
String?) are omitted from therequiredarray.
Limitations
- Custom DTO generation: Custom classes in parameters currently fallback to
{"type": "object"}. Deep nested schema generation for custom DTOs is not yet supported. - Unsupported Types: Core classes like
Stream,Socket,File, andFuturecannot be used as tool parameters.
语言Dart
分类
如何选择适合项目的代码仓?
先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。
- 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
- 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
- 使用前在 GitHub 核对 README、许可证与 Issues。
来源与维护
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗