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:
Stephen Toub 2025-06-16 19:39:41 -04:00 • committed by GitHub
commit 2bcff315f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -46,11 +46,7 @@ public class Program
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,
@ -173,16 +169,16 @@ public class Program
{
throw new McpException("Missing required argument 'message'", McpErrorCode.InvalidParams);
}
return new CallToolResponse()
return new CallToolResult()
{
Content = [new Content() { Text = "Echo: " + message.ToString(), Type = "text" }]
Content = [new TextContentBlock { Text = $"Echo: {message}" }]
};
}
else if (request.Params.Name == "echoSessionId")
{
return new CallToolResponse()
return new CallToolResult()
{
Content = [new Content() { Text = request.Server.SessionId, Type = "text" }]
Content = [new TextContentBlock { Text = request.Server.SessionId ?? string.Empty }]
};
}
else if (request.Params.Name == "sampleLLM")
@ -196,9 +192,9 @@ public class Program
var sampleResult = await request.Server.SampleAsync(CreateRequestSamplingParams(prompt.ToString(), "sampleLLM", Convert.ToInt32(maxTokens.ToString())),
cancellationToken);
return new CallToolResponse()
return new CallToolResult()
{
Content = [new Content() { Text = $"LLM sampling result: {sampleResult.Content.Text}", Type = "text" }]
Content = [new TextContentBlock { Text = $"LLM sampling result: {(sampleResult.Content as TextContentBlock)?.Text}" }]
};
}
else
@ -308,8 +304,8 @@ public class Program
{
Name = "complex_prompt",
Description = "A prompt with arguments",
Arguments = new()
{
Arguments =
[
new PromptArgument()
{
Name = "temperature",
@ -322,7 +318,7 @@ public class Program
Description = "Output style",
Required = false
}
}
],
}
]
};
@ -339,11 +335,7 @@ public class Program
messages.Add(new PromptMessage()
{
Role = Role.User,
Content = new Content()
{
Type = "text",
Text = "This is a simple prompt without arguments."
}
Content = new TextContentBlock { Text = "This is a simple prompt without arguments." },
});
}
else if (request.Params.Name == "complex_prompt")
@ -353,27 +345,18 @@ public class Program
messages.Add(new PromptMessage()
{
Role = Role.User,
Content = new Content()
{
Type = "text",
Text = $"This is a complex prompt with arguments: temperature={temperature}, style={style}"
}
Content = new TextContentBlock { Text = $"This is a complex prompt with arguments: temperature={temperature}, style={style}" },
});
messages.Add(new PromptMessage()
{
Role = Role.Assistant,
Content = new Content()
{
Type = "text",
Text = "I understand. You've provided a complex prompt with temperature and style arguments. How would you like me to proceed?"
}
Content = new TextContentBlock { Text = "I understand. You've provided a complex prompt with temperature and style arguments. How would you like me to proceed?" },
});
messages.Add(new PromptMessage()
{
Role = Role.User,
Content = new Content()
Content = new ImageContentBlock()
{
Type = "image",
Data = MCP_TINY_IMAGE,
MimeType = "image/png"
}