Update content according to latest spec (#513)
* Update content according to latest spec * Add Title to a bunch of types * Add _meta to lots of types * Address feedback, more cleanup, fix NAOT test failure
This commit is contained in:
parent
28d65470f4
commit
2bcff315f8
4 changed files with 1700 additions and 853 deletions
|
|
@ -86,9 +86,9 @@ builder.Services
|
|||
var @ref = @params.Ref;
|
||||
var argument = @params.Argument;
|
||||
|
||||
if (@ref.Type == "ref/resource")
|
||||
if (@ref is ResourceTemplateReference rtr)
|
||||
{
|
||||
var resourceId = @ref.Uri?.Split("/").Last();
|
||||
var resourceId = rtr.Uri?.Split("/").Last();
|
||||
|
||||
if (resourceId is null)
|
||||
{
|
||||
|
|
@ -103,7 +103,7 @@ builder.Services
|
|||
};
|
||||
}
|
||||
|
||||
if (@ref.Type == "ref/prompt")
|
||||
if (@ref is PromptReference pr)
|
||||
{
|
||||
if (!exampleCompletions.TryGetValue(argument.Name, out IEnumerable<string>? value))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,25 +15,22 @@ public class AnnotatedMessageTool
|
|||
}
|
||||
|
||||
[McpServerTool(Name = "annotatedMessage"), Description("Generates an annotated message")]
|
||||
public static IEnumerable<Content> AnnotatedMessage(MessageType messageType, bool includeImage = true)
|
||||
public static IEnumerable<ContentBlock> AnnotatedMessage(MessageType messageType, bool includeImage = true)
|
||||
{
|
||||
List<Content> contents = messageType switch
|
||||
List<ContentBlock> contents = messageType switch
|
||||
{
|
||||
MessageType.Error => [new()
|
||||
MessageType.Error => [new TextContentBlock
|
||||
{
|
||||
Type = "text",
|
||||
Text = "Error: Operation failed",
|
||||
Annotations = new() { Audience = [Role.User, Role.Assistant], Priority = 1.0f }
|
||||
}],
|
||||
MessageType.Success => [new()
|
||||
MessageType.Success => [new TextContentBlock
|
||||
{
|
||||
Type = "text",
|
||||
Text = "Operation completed successfully",
|
||||
Annotations = new() { Audience = [Role.User], Priority = 0.7f }
|
||||
}],
|
||||
MessageType.Debug => [new()
|
||||
MessageType.Debug => [new TextContentBlock
|
||||
{
|
||||
Type = "text",
|
||||
Text = "Debug: Cache hit ratio 0.95, latency 150ms",
|
||||
Annotations = new() { Audience = [Role.Assistant], Priority = 0.3f }
|
||||
}],
|
||||
|
|
@ -42,9 +39,8 @@ public class AnnotatedMessageTool
|
|||
|
||||
if (includeImage)
|
||||
{
|
||||
contents.Add(new()
|
||||
contents.Add(new ImageContentBlock()
|
||||
{
|
||||
Type = "image",
|
||||
Data = TinyImageTool.MCP_TINY_IMAGE.Split(",").Last(),
|
||||
MimeType = "image/png",
|
||||
Annotations = new() { Audience = [Role.User], Priority = 0.5f }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class LongRunningTool
|
|||
int duration = 10,
|
||||
int steps = 5)
|
||||
{
|
||||
var progressToken = context.Params?.Meta?.ProgressToken;
|
||||
var progressToken = context.Params?.ProgressToken;
|
||||
var stepDuration = duration / steps;
|
||||
|
||||
for (int i = 1; i <= steps + 1; i++)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class SampleLlmTool
|
|||
var samplingParams = CreateRequestSamplingParams(prompt ?? string.Empty, "sampleLLM", maxTokens);
|
||||
var sampleResult = await server.SampleAsync(samplingParams, cancellationToken);
|
||||
|
||||
return $"LLM sampling result: {sampleResult.Content.Text}";
|
||||
return $"LLM sampling result: {(sampleResult.Content as TextContentBlock)?.Text}";
|
||||
}
|
||||
|
||||
private static CreateMessageRequestParams CreateRequestSamplingParams(string context, string uri, int maxTokens = 100)
|
||||
|
|
@ -27,11 +27,7 @@ public class SampleLlmTool
|
|||
Messages = [new SamplingMessage()
|
||||
{
|
||||
Role = Role.User,
|
||||
Content = new Content()
|
||||
{
|
||||
Type = "text",
|
||||
Text = $"Resource {uri} context: {context}"
|
||||
}
|
||||
Content = new TextContentBlock { Text = $"Resource {uri} context: {context}" },
|
||||
}],
|
||||
SystemPrompt = "You are a helpful test server.",
|
||||
MaxTokens = maxTokens,
|
||||
|
|
|
|||
Loading…
Reference in a new issue