-
Notifications
You must be signed in to change notification settings - Fork 3.7k
MCP server feature added to the CLI #24594
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: dev
Are you sure you want to change the base?
Conversation
Introduces the McpCommand for running a local MCP server and outputting client configuration for AI tool integration. Registers the new command in AbpCliCoreModule.
Introduces a new MCP server mode to the ABP CLI, including a JSON-RPC server implementation, health checks, and configuration output. Adds supporting services for HTTP communication and configuration models, and updates the CLI to suppress the banner for MCP commands to avoid corrupting the JSON-RPC stream.
Introduces McpToolDefinition model and McpToolsCacheService to fetch and cache tool definitions from the server, with fallback to cache if the server is unavailable. Updates McpServerService to dynamically register tools based on cached or fetched definitions, and adds related constants and paths. This enables more flexible and up-to-date tool management in the MCP server.
Introduces McpToolDefinitionValidator to validate and filter tool definitions before caching. Updates McpHttpClientService to support configurable MCP server URLs and sanitizes error messages. Enhances McpToolsCacheService to use validated tools, adds restrictive file permissions for cache, and improves error handling and logging. Updates CliConsts with new constants for MCP server configuration.
Enhanced error handling and user messaging in MCP HTTP client and server services, providing sanitized and user-friendly error responses for network, timeout, and unexpected errors. Updated MCP command to enforce license validation before tool execution. Improved cross-platform file permission handling in the tools cache service.
Added IMcpLogger interface and McpLogger implementation to provide structured logging for MCP operations, supporting log levels and file rotation. Replaced direct Console.Error logging with IMcpLogger in MCP-related services and commands. Log level is now configurable via the ABP_MCP_LOG_LEVEL environment variable, and logs are written to both file and stderr as appropriate.
Extracted license validation logic in McpCommand to a dedicated method for reuse and clarity. Improved executable path resolution by splitting logic into helper methods. In McpHttpClientService, centralized HTTP exception handling and replaced repeated code with a single method. Refactored tool invocation in McpServerService to use a dedicated handler, improving error handling and logging. Simplified log level parsing in McpLogger for better maintainability.
Updated the command option and help text from 'getconfig' to 'get-config' for consistency and improved readability.
Introduced ITelemetryService to McpCommand and added activity tracking using ActivityNameConsts.AbpCliCommandsMcp. Also updated ActivityNameConsts to include the new activity name constant for MCP command telemetry.
Replaced hardcoded TestServerUrl with awaitable GetMcpServerUrlAsync() in CallToolAsync, CheckServerHealthAsync, and GetToolDefinitionsAsync methods to ensure the correct server URL is used dynamically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds MCP (Model Context Protocol) server functionality to the ABP CLI, enabling AI tools to interact with ABP.IO services through a standardized protocol. The feature introduces a new abp mcp command that runs a local stdio MCP server, which acts as a bridge between MCP clients (like AI assistants) and the ABP.IO backend.
Key changes:
- New
abp mcpcommand with two modes: server mode (default) and config output mode (get-config) - HTTP client service with caching, validation, and fallback mechanisms for fetching tool definitions from ABP.IO MCP server
- Local MCP server implementation using the ModelContextProtocol library that dynamically registers tools from the backend
- Custom logging system (file + stderr) to avoid corrupting the stdio JSON-RPC communication stream
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/ActivityNameConsts.cs | Added telemetry constant for MCP command tracking |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpToolsCacheService.cs | Implements 24-hour caching of tool definitions with fallback support |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpToolDefinitionValidator.cs | Validates tool definitions from server (names, schemas, properties) |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpServerService.cs | Core MCP server that registers and executes tools via stdio transport |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpLogger.cs | File and stderr logging to avoid stdout corruption |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpHttpClientService.cs | HTTP client for communicating with ABP.IO MCP server |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/IMcpLogger.cs | Logger interface for MCP operations |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Models/McpToolDefinition.cs | Model classes for tool definitions, schemas, and properties |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Models/McpClientConfiguration.cs | Model for MCP client configuration JSON output |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/McpCommand.cs | Main command implementation with license validation and server lifecycle |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs | Modified to silently skip MCP command to avoid stdout corruption |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CommandSelector.cs | Updated to handle MCP command specially |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs | Modified to suppress banner and version check for MCP command |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs | Added paths for MCP cache and log files |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliConsts.cs | Added MCP-related constants (URLs, environment variables, memory keys) |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs | Registered MCP command in CLI options |
| framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj | Added ModelContextProtocol package reference |
| Directory.Packages.props | Added ModelContextProtocol 0.5.0-preview.1 package version |
| .gitignore | Added framework/.cursor to gitignore |
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/ActivityNameConsts.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpServerService.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpServerService.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpHttpClientService.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpHttpClientService.cs
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpHttpClientService.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Models/McpToolDefinition.cs
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpHttpClientService.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpToolsCacheService.cs
Outdated
Show resolved
Hide resolved
Extracted AbpMcpServerTool to its own file and improved tool name validation in McpHttpClientService. Enhanced error handling and logging, made cache validity configurable, and fixed typos in ActivityNameConsts for AbpCli command telemetry constants.
Deleted the hardcoded TestServerUrl constant from McpHttpClientService as it is no longer needed after testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 19 out of 20 changed files in this pull request and generated 12 comments.
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpToolsCacheService.cs
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpToolDefinitionValidator.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpHttpClientService.cs
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/McpCommand.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpToolDefinitionValidator.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpHttpClientService.cs
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpLogger.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpServerService.cs
Show resolved
Hide resolved
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpToolsCacheService.cs
Show resolved
Hide resolved
Introduces CommandLineArgsExtensions for MCP command detection, removes McpToolDefinitionValidator, and updates MCP tool definition fetching to require a successful server connection. Cleans up unused environment variables, adds mcp-config.json support, and simplifies tool validation and caching logic. These changes improve reliability and maintainability of MCP command execution and tool management.
Replaces the hardcoded localhost URL with the cached server URL in GetMcpServerUrlAsync, enabling dynamic server address resolution.
Refactored McpLogger to use ILogger and Serilog for file logging, removing manual file handling and rotation. Enhanced debug logging in McpHttpClientService and added explicit tool name initialization from cache. Updated Program.cs to use a separate log file for MCP mode. Improved error logging in McpServerService for tool execution failures.
Description
Main issue vs-internal issue 7864
Related to vs-internal PR 7820
This PR is dependent on the related vs-internal PR I mentioned above. In order to test and release this feature, other PR need to be tested and released first.
abp mcpcommand addedChecklist