Skip to content

MCP Feature added to CLI#24677

Merged
MansurBesleney merged 26 commits intorel-10.1from
mansur-cli-mcp
Jan 21, 2026
Merged

MCP Feature added to CLI#24677
MansurBesleney merged 26 commits intorel-10.1from
mansur-cli-mcp

Conversation

@MansurBesleney
Copy link
Contributor

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.

  • Local stdio MCP server feature added to the CLI
  • New abp mcp command added

Checklist

  • I fully tested it as a developer.
  • I will create a separate documentation issue.

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.
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.
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.
Introduces an optional OutputSchema property to McpToolDefinition and updates AbpMcpServerTool and McpServerService to handle and register tools with output schemas. This enables tools to define and expose their output schema alongside input schema for improved contract clarity.
@MansurBesleney MansurBesleney added this to the 10.1-final milestone Jan 19, 2026
@MansurBesleney MansurBesleney self-assigned this Jan 19, 2026
Copilot AI review requested due to automatic review settings January 19, 2026 12:58
@MansurBesleney
Copy link
Contributor Author

Related pr

Copy link
Contributor

Copilot AI left a 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 PR adds MCP (Model Context Protocol) support to the ABP CLI, enabling the CLI to act as a local stdio MCP server that integrates with AI tools like Claude Desktop and VS Code Copilot. The feature allows authenticated ABP users with valid licenses to expose ABP-specific tools through the MCP protocol by communicating with a remote ABP.IO MCP server.

Changes:

  • Adds new abp mcp command with support for running the MCP server and generating client configuration
  • Implements caching layer for tool definitions with 24-hour validity
  • Adds special logging configuration for MCP to prevent stdout corruption (JSON-RPC protocol requirement)

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
ActivityNameConsts.cs Adds telemetry constant for MCP command
Program.cs Configures separate log file for MCP command to avoid stdout contamination
McpToolsCacheService.cs Implements caching for tool definitions with 24-hour expiration
McpServerService.cs Core MCP server implementation using stdio transport
McpLogger.cs Custom logger that writes to stderr and file (not stdout)
McpHttpClientService.cs HTTP client for communicating with remote ABP.IO MCP server
IMcpLogger.cs Logger interface for MCP operations
AbpMcpServerTool.cs Tool wrapper for MCP protocol
McpToolDefinition.cs Models for tool definitions and schemas
McpClientConfiguration.cs Configuration model for MCP clients
McpCommand.cs Main command implementation with license validation
HelpCommand.cs Updated to avoid stdout corruption for MCP
CommandSelector.cs Special handling for MCP command routing
CliService.cs Integration of MCP-specific error handling
CliPaths.cs Adds paths for MCP cache, config, and logs
CliConsts.cs Adds MCP-related constants
CommandLineArgsExtensions.cs Helper extension for detecting MCP command
AbpCliCoreModule.cs Registers MCP command
Volo.Abp.Cli.Core.csproj Adds ModelContextProtocol package dependency
Directory.Packages.props Defines ModelContextProtocol version (0.5.0-preview.1)
.gitignore Adds IDE-specific ignore entry

Updated the argument comparison for 'mcp' to use case-insensitive matching with StringComparison.OrdinalIgnoreCase. This improves usability by allowing users to enter 'mcp' in any letter case.
private void RegisterToolFromDefinition(McpServerOptions options, McpToolDefinition toolDef)
{
// Convert McpToolDefinition to the input schema format expected by MCP
var inputSchemaObject = new Dictionary<string, object>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we generate an input schema again when we already had an input schema?

Comment on lines +20 to +24
// Don't fall back to HelpCommand for MCP command to avoid corrupting stdout JSON-RPC stream
if (commandLineArgs.IsMcpCommand())
{
return Options.Commands.GetOrDefault("mcp") ?? typeof(HelpCommand);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn’t be necessary.

Comment on lines +35 to +41
// Don't output help text for MCP command to avoid corrupting stdout JSON-RPC stream
// If MCP command is being used, it should have been handled directly, not through HelpCommand
if (commandLineArgs.IsMcpCommand())
{
// Silently return - MCP server should handle its own errors
return Task.CompletedTask;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we cancel the help command?

Copy link
Contributor

Copilot AI left a 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 20 out of 21 changed files in this pull request and generated 6 comments.

Removed special-case handling for MCP commands in CommandSelector and HelpCommand to simplify logic. In McpHttpClientService, reorganized private methods and classes for better code structure and maintainability. Made ConvertProperties static in McpServerService and clarified comments regarding MCP JSON schema requirements.
Set default 'Type' property in McpToolInputSchema and pass the schema object directly instead of building a dictionary. Use camelCase JSON serialization for input schemas in McpServerService to ensure correct property naming.
@gizemmutukurt gizemmutukurt removed the request for review from EngincanV January 20, 2026 13:41
@MansurBesleney MansurBesleney merged commit 508f7d5 into rel-10.1 Jan 21, 2026
2 of 3 checks passed
@MansurBesleney MansurBesleney deleted the mansur-cli-mcp branch January 21, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants