-
Notifications
You must be signed in to change notification settings - Fork 224
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
Open
PabloTortosaLopez
wants to merge
22
commits into
main
Choose a base branch
from
feat/mcp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,433
−0
Open
feat: add custom MCP #1416
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1832e66
feat: init mcp
ryzizub 50fc6d2
refactor: refactored MCP server to use VeryGoodCommandRunner and mino…
PabloTortosaLopez 5a7dcfb
chore: expand tool descriptions and input schema details
PabloTortosaLopez 75499d6
feat: fixed create tool description and arguments
RuiMiguel 82a42e5
feat: fixed test tool description and arguments
RuiMiguel 22acc65
fix: changed some create arguments descriptions
RuiMiguel 0901974
fix: improved some descriptions
RuiMiguel b2a8709
fix: doc and fix tests
RuiMiguel ed8d211
fix: test coverage for mcp_command
RuiMiguel 21f881f
fix: test coverage for mcp_command
RuiMiguel 2a79d5e
fix: tests and coverage for mcp_server
RuiMiguel 889189e
fix: exclude-covereage fix and test coverage
RuiMiguel 886b3e5
fix: fixed exclude_coverage schema
RuiMiguel 78f5138
chore: removed unreachable exception blocks in each handle command
PabloTortosaLopez dcf3649
refactor: extract cliArgs to improve readability
PabloTortosaLopez 2015745
Merge branch 'main' into feat/mcp
PabloTortosaLopez e97f60d
chore: rename packages_check tool to packages_check_licenses and mino…
PabloTortosaLopez 9431269
chore: remove unnecessary comments in mcp_server.dart
PabloTortosaLopez 6bc56e1
chore: remove unnecessary comments about stream_channel dependency
PabloTortosaLopez 731ac35
chore: update MCP tool names and links in README
PabloTortosaLopez 546b070
chore: added experimental warning for mcp at README
RuiMiguel f29cb5e
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.