Skip to content

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.
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 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 mcp command 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

@salihozkara salihozkara requested review from EngincanV and removed request for salihozkara January 9, 2026 11:23
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.
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 19 out of 20 changed files in this pull request and generated 12 comments.

@ebicoglu ebicoglu requested a review from salihozkara January 12, 2026 06:20
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.
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.

3 participants