-
Notifications
You must be signed in to change notification settings - Fork 10
Adding MCP Annotation and MCP Generator #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Adding MCP Annotation and MCP Generator #122
Conversation
- Introduced `mcp_annotations` for declaring MCP tools and servers with annotations. - Added `mcp_codegen` for generating boilerplate code from annotations. - Updated README to include new packages and their descriptions. - Created a demo server example showcasing the use of MCP annotations and code generation. - Added build configuration for the code generation process.
- Simplified the constructor of MCPDemoServer to a constant constructor. - Streamlined the add method to use a concise arrow function for better readability.
- Introduced a new code generation framework for MCP servers and tools. - Added `HandlerBuilder`, `ServerBuilder`, `SchemaBuilder`, and `CodeEmitter` classes to facilitate the generation of server and tool code. - Implemented `AnnotationScanner` and `ToolScanner` for scanning libraries for MCP annotations. - Refactored `MCPGenerator` to utilize the new builders and scanners for cleaner code generation. - Added utility methods for handling annotations and generating schemas for tool parameters.
- Updated `HandlerBuilder` and `ServerBuilder` to improve code generation logic, including changes to argument handling. - Introduced new test files for `HandlerBuilder`, `SchemaBuilder`, `ServerBuilder`, and scanners to ensure proper functionality and coverage. - Added utility tests for annotation detection and tool registration.
- Removed unused element warnings and simplified input schema property definitions for better clarity. - Streamlined the data transformation logic in the server setup for improved readability. - Cleaned up comments to enhance code maintainability.
- Added copyright headers to multiple test files in the mcp_codegen package to comply with licensing requirements.
- Changed the `myServer` function to a `MyServer` class with a constant constructor and an `add` method annotated with `@MCPTool()`. - Updated the test expectation to reflect the new class name.
- Updated `pubspec.yaml` in the demo server to use versioned dependencies for `dart_mcp` and `mcp_annotations`. - Added `mcp_codegen` as a dev dependency. - Refactored `main.dart` to simplify the `add` method and removed the unused `strlen` method. - Added changelogs and licenses for `mcp_annotations` and `mcp_codegen` packages, marking their initial release. - Updated `pubspec.yaml` for both packages to reflect version changes.
Hi! This looks cool and definitely reduces some of the boilerplate around setting up servers. I think the main question is just whether it is something we want to own/support at this time - code generators do tend to be a fair bit of maintenance due to keeping up with the language and analyzer API evolution, as well as just being fairly complex and tending to get a lot of requests for new features so they tend to grow in complexity a lot. With the rapidly evolving nature of dart_mcp I also worry we willl have lots of churn in the code generator. @kenzieschmoll thoughts? |
Thanks for the thoughtful feedback @jakemac53 — I totally understand your concerns about ownership and maintenance, especially given how quickly Dart and I'm happy to handle ongoing maintenance for the generator here, including keeping it updated with language changes and analyzer APIs. If I ever need to step away, I'll either find a new maintainer or help gracefully deprecate the package. If integrating the generator directly into
I'm really engaged with the project, so I'm also happy to contribute to other issues or priorities you might have—just let me know where else I could help! Looking forward to hearing your thoughts, especially from @kenzieschmoll! |
I think from my perspective, letting you run with the package in your own repo but mentioning it in the readme is a good option for us (and you actually, you won't have to wait on us for reviews which might be a bit slow due to this being lower priority for us than the core SDK bits). But, lets see what Kenzie says as well 👍 |
I agree with @jakemac53. I think the best path forward is to leave this in a separate package in your own repo. We can discuss adding a reference in the For this reference, I would just want to be clear about our promises WRT to production quality and ongoing support for any third party packages we link to in the README, basically stating that we, the Dart team, do not make any promises about quality, support, or maintenance, and that users should perform their own investigation before using any of the linked third party packages. This note should also clarify that we may link to other third party packages in this section on a case-by-case basis. |
@nelsoncampos-cloudwalk how does that sound? |
This sounds good — thanks for the thoughtful discussion @jakemac53 and @kenzieschmoll! I'll create a separate repo for the generator and share the link here soon. Once that's set, we can close this PR. Then, I can either open a new PR to add the link to the README or leave it to you — whatever's easier for you. Thanks again for your time, support, and guidance! |
Hi Dart team! This PR adds automatic code‑generation for MCP servers, making setup quicker and cleaner. Hope it helps—thanks for the awesome project!
mcp_annotations
for declaring MCP tools and servers with annotations.mcp_codegen
for generating boilerplate code from annotations.Here it's a demo:
Screen.Recording.2025-05-10.at.14.16.19.1.mp4
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.