Implement MCP task support (SEP-1686) (#1170)
Co-authored-by: Stephen Halter <halter73@gmail.com>
This commit is contained in:
parent
81664c3fce
commit
10e4f5b20f
1 changed files with 11580 additions and 46 deletions
|
|
@ -150,6 +150,27 @@ public class Program
|
|||
"required": ["prompt", "maxTokens"]
|
||||
}
|
||||
"""),
|
||||
},
|
||||
new Tool
|
||||
{
|
||||
Name = "longRunning",
|
||||
Description = "Simulates a long-running operation that supports task-based execution.",
|
||||
InputSchema = JsonElement.Parse("""
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"durationMs": {
|
||||
"type": "number",
|
||||
"description": "Duration of the operation in milliseconds"
|
||||
}
|
||||
},
|
||||
"required": ["durationMs"]
|
||||
}
|
||||
"""),
|
||||
Execution = new ToolExecution
|
||||
{
|
||||
TaskSupport = ToolTaskSupport.Optional
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
@ -194,6 +215,19 @@ public class Program
|
|||
Content = [new TextContentBlock { Text = $"LLM sampling result: {sampleResult.Content.OfType<TextContentBlock>().FirstOrDefault()?.Text}" }]
|
||||
};
|
||||
}
|
||||
else if (request.Params.Name == "longRunning")
|
||||
{
|
||||
if (request.Params.Arguments is null || !request.Params.Arguments.TryGetValue("durationMs", out var durationMsValue))
|
||||
{
|
||||
throw new McpProtocolException("Missing required argument 'durationMs'", McpErrorCode.InvalidParams);
|
||||
}
|
||||
int durationMs = Convert.ToInt32(durationMsValue.ToString());
|
||||
await Task.Delay(durationMs, cancellationToken);
|
||||
return new CallToolResult
|
||||
{
|
||||
Content = [new TextContentBlock { Text = $"Long-running operation completed after {durationMs}ms" }]
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new McpProtocolException($"Unknown tool: '{request.Params.Name}'", McpErrorCode.InvalidParams);
|
||||
|
|
|
|||
Loading…
Reference in a new issue