Browse Source

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.
pull/24677/head
Mansur Besleney 3 weeks ago
parent
commit
39ffd978de
  1. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Models/McpToolDefinition.cs
  2. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpMcpServerTool.cs
  3. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/McpServerService.cs

2
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

6
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<RequestContext<CallToolRequestParams>, CancellationToken, ValueTask<CallToolResult>> _handler;
public AbpMcpServerTool(
string name,
string description,
JsonElement inputSchema,
JsonElement? outputSchema,
Func<RequestContext<CallToolRequestParams>, CancellationToken, ValueTask<CallToolResult>> 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<object> Metadata => Array.Empty<object>();

6
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<string>()
};
RegisterTool(options, toolDef.Name, toolDef.Description, inputSchemaObject);
RegisterTool(options, toolDef.Name, toolDef.Description, inputSchemaObject, toolDef.OutputSchema);
}
private Dictionary<string, object> ConvertProperties(Dictionary<string, McpToolProperty> 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)
);

Loading…
Cancel
Save