From 39ffd978ded74e60bafb5821b352b13d2dbb4407 Mon Sep 17 00:00:00 2001 From: Mansur Besleney Date: Mon, 19 Jan 2026 15:37:19 +0300 Subject: [PATCH] Add OutputSchema support to MCP tool definitions 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. --- .../Volo/Abp/Cli/Commands/Models/McpToolDefinition.cs | 2 ++ .../Volo/Abp/Cli/Commands/Services/AbpMcpServerTool.cs | 6 +++++- .../Volo/Abp/Cli/Commands/Services/McpServerService.cs | 6 ++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Models/McpToolDefinition.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Models/McpToolDefinition.cs index 1c76a805b1..787b4e3802 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Models/McpToolDefinition.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Models/McpToolDefinition.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text.Json; namespace Volo.Abp.Cli.Commands.Models; @@ -7,6 +8,7 @@ public class McpToolDefinition public string Name { get; set; } public string Description { get; set; } public McpToolInputSchema InputSchema { get; set; } + public JsonElement? OutputSchema { get; set; } } public class McpToolInputSchema diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpMcpServerTool.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpMcpServerTool.cs index 71f0f206f6..6858cf7571 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpMcpServerTool.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpMcpServerTool.cs @@ -13,17 +13,20 @@ internal class AbpMcpServerTool : McpServerTool private readonly string _name; private readonly string _description; private readonly JsonElement _inputSchema; + private readonly JsonElement? _outputSchema; private readonly Func, CancellationToken, ValueTask> _handler; public AbpMcpServerTool( string name, string description, JsonElement inputSchema, + JsonElement? outputSchema, Func, CancellationToken, ValueTask> handler) { _name = name; _description = description; _inputSchema = inputSchema; + _outputSchema = outputSchema; _handler = handler; } @@ -31,7 +34,8 @@ internal class AbpMcpServerTool : McpServerTool { Name = _name, Description = _description, - InputSchema = _inputSchema + InputSchema = _inputSchema, + OutputSchema = _outputSchema }; public override IReadOnlyList Metadata => Array.Empty(); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpServerService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpServerService.cs index a591c42371..7be6af6688 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpServerService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpServerService.cs @@ -82,7 +82,7 @@ public class McpServerService : ITransientDependency ["required"] = toolDef.InputSchema?.Required ?? new List() }; - RegisterTool(options, toolDef.Name, toolDef.Description, inputSchemaObject); + RegisterTool(options, toolDef.Name, toolDef.Description, inputSchemaObject, toolDef.OutputSchema); } private Dictionary ConvertProperties(Dictionary properties) @@ -121,7 +121,8 @@ public class McpServerService : ITransientDependency McpServerOptions options, string name, string description, - object inputSchema) + object inputSchema, + JsonElement? outputSchema) { if (options.ToolCollection == null) { @@ -132,6 +133,7 @@ public class McpServerService : ITransientDependency name, description, JsonSerializer.SerializeToElement(inputSchema), + outputSchema, (context, cancellationToken) => HandleToolInvocationAsync(name, context, cancellationToken) );