-
Notifications
You must be signed in to change notification settings - Fork 228
feat: add custom MCP #1416
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
Merged
Merged
feat: add custom MCP #1416
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9bfff1f
feat: init mcp
ryzizub 461c612
refactor: refactored MCP server to use VeryGoodCommandRunner and mino…
PabloTortosaLopez 328038d
chore: expand tool descriptions and input schema details
PabloTortosaLopez b25d8ce
feat: fixed create tool description and arguments
RuiMiguel b172bae
feat: fixed test tool description and arguments
RuiMiguel 7bacd90
fix: changed some create arguments descriptions
RuiMiguel 150a837
fix: improved some descriptions
RuiMiguel a24ad6e
fix: doc and fix tests
RuiMiguel d3bf408
fix: test coverage for mcp_command
RuiMiguel 55d67eb
fix: test coverage for mcp_command
RuiMiguel 95fcf66
fix: tests and coverage for mcp_server
RuiMiguel c341d48
fix: exclude-covereage fix and test coverage
RuiMiguel f083896
fix: fixed exclude_coverage schema
RuiMiguel 8f7195f
chore: removed unreachable exception blocks in each handle command
PabloTortosaLopez 649b9aa
refactor: extract cliArgs to improve readability
PabloTortosaLopez b883d4a
chore: rename packages_check tool to packages_check_licenses and mino…
PabloTortosaLopez 6a3ce2c
chore: remove unnecessary comments in mcp_server.dart
PabloTortosaLopez e40d20e
chore: remove unnecessary comments about stream_channel dependency
PabloTortosaLopez 170b1da
chore: update MCP tool names and links in README
PabloTortosaLopez bf9e320
chore: added experimental warning for mcp at README
RuiMiguel a83b285
fix: added experimental warning message to cli help
RuiMiguel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export 'mcp_command.dart'; | ||
| export 'mcp_server.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import 'dart:async'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:args/command_runner.dart'; | ||
| import 'package:dart_mcp/server.dart'; | ||
| import 'package:dart_mcp/stdio.dart'; | ||
| import 'package:mason/mason.dart'; | ||
| import 'package:stream_channel/stream_channel.dart'; | ||
| import 'package:very_good_cli/src/mcp/mcp_server.dart'; | ||
|
|
||
| /// Type definition for a factory that creates a [VeryGoodMCPServer]. | ||
| typedef ServerFactory = | ||
| MCPServer Function({ | ||
| required StreamChannel<String> channel, | ||
| required Logger logger, | ||
| }); | ||
|
|
||
| /// Factory function to create a [StreamChannel] from input and output streams. | ||
| typedef ChannelFactory = StreamChannel<String> Function(); | ||
|
|
||
| // Private default implementation for the channel factory | ||
| StreamChannel<String> _defaultChannelFactory() { | ||
| return stdioChannel(input: stdin, output: stdout); | ||
| } | ||
|
|
||
| /// {@template mcp_command} | ||
| /// `very_good mcp` command starts the MCP (Model Context Protocol) server. | ||
| /// {@endtemplate} | ||
| class MCPCommand extends Command<int> { | ||
| /// {@macro mcp_command} | ||
| MCPCommand({ | ||
| Logger? logger, | ||
| ChannelFactory? channelFactory, | ||
| ServerFactory? serverFactory, | ||
| }) : _logger = logger ?? Logger(), | ||
| _channelFactory = channelFactory ?? _defaultChannelFactory, | ||
| _serverFactory = serverFactory ?? VeryGoodMCPServer.new; | ||
|
|
||
| /// The [name] of the command. But static. | ||
| static const String commandName = 'mcp'; | ||
|
|
||
| @override | ||
| String get description => ''' | ||
| Start the MCP (Model Context Protocol) server. WARNING: This is an experimental package and may change or become unstable without notice. Use it with caution at your own risk.'''; | ||
|
|
||
| @override | ||
| String get name => commandName; | ||
|
|
||
| final Logger _logger; | ||
|
|
||
| final ChannelFactory _channelFactory; | ||
|
|
||
| final ServerFactory _serverFactory; | ||
|
|
||
| @override | ||
| Future<int> run() async { | ||
| try { | ||
| _logger | ||
| ..info('Starting Very Good CLI MCP Server...') | ||
| ..info( | ||
| 'Server will listen on stdin/stdout for MCP protocol messages', | ||
| ); | ||
|
|
||
| // Create a channel from stdin/stdout using the stdio helper | ||
| final channel = _channelFactory(); | ||
|
|
||
| // Create and start the MCP server | ||
| final server = _serverFactory( | ||
| channel: channel, | ||
| logger: _logger, | ||
| ); | ||
|
|
||
| _logger | ||
| ..info('MCP Server started successfully') | ||
| ..info('Available tools:') | ||
| ..info(''' | ||
| - create: Create a very good Dart or Flutter project in seconds based on the provided template. Each template has a corresponding sub-command.''') | ||
omartinma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ..info(' - test: Run tests in a Dart or Flutter project.') | ||
| ..info( | ||
| ''' | ||
| - packages_get: Install or update Dart/Flutter package dependencies. | ||
| Use after creating a project or modifying pubspec.yaml. | ||
| Supports recursive installation and package exclusion.''', | ||
| ) | ||
| ..info( | ||
| ''' | ||
| - packages_check_licenses: Verify package licenses for compliance and validation in a Dart or Flutter project. | ||
| Identifies license types (MIT, BSD, Apache, etc.) for all | ||
| dependencies. Use to ensure license compatibility.''', | ||
| ); | ||
|
|
||
| // Wait for the server to complete | ||
| // (this will block until the connection is closed) | ||
| await server.done; | ||
|
|
||
| return ExitCode.success.code; | ||
| } on Exception catch (e, stackTrace) { | ||
| _logger | ||
| ..err('Failed to start MCP server: $e') | ||
| ..err('Stack trace: $stackTrace'); | ||
| return ExitCode.software.code; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.