Add McpClient/Session methods using .Protocol types (#1063)
This commit is contained in:
parent
d76bc16bd1
commit
4a84412331
3 changed files with 1116 additions and 639 deletions
|
|
@ -14,7 +14,7 @@ public sealed class InteractiveTools
|
|||
[McpServerTool, Description("A simple game where the user has to guess a number between 1 and 10.")]
|
||||
public async Task<string> GuessTheNumber(
|
||||
McpServer server, // Get the McpServer from DI container
|
||||
CancellationToken token
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
// Check if the client supports elicitation
|
||||
|
|
@ -37,7 +37,7 @@ public sealed class InteractiveTools
|
|||
{
|
||||
Message = "Do you want to play a game?",
|
||||
RequestedSchema = playSchema
|
||||
}, token);
|
||||
}, cancellationToken);
|
||||
|
||||
// Check if user wants to play
|
||||
if (playResponse.Action != "accept" || playResponse.Content?["Answer"].ValueKind != JsonValueKind.True)
|
||||
|
|
@ -64,7 +64,7 @@ public sealed class InteractiveTools
|
|||
{
|
||||
Message = "What is your name?",
|
||||
RequestedSchema = nameSchema
|
||||
}, token);
|
||||
}, cancellationToken);
|
||||
|
||||
if (nameResponse.Action != "accept")
|
||||
{
|
||||
|
|
@ -100,7 +100,7 @@ public sealed class InteractiveTools
|
|||
{
|
||||
Message = message,
|
||||
RequestedSchema = guessSchema
|
||||
}, token);
|
||||
}, cancellationToken);
|
||||
|
||||
if (guessResponse.Action != "accept")
|
||||
{
|
||||
|
|
@ -128,7 +128,7 @@ public sealed class InteractiveTools
|
|||
[McpServerTool, Description("Example tool demonstrating various enum schema types")]
|
||||
public async Task<string> EnumExamples(
|
||||
McpServer server,
|
||||
CancellationToken token
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
// Example 1: UntitledSingleSelectEnumSchema - Simple enum without display titles
|
||||
|
|
@ -150,7 +150,7 @@ public sealed class InteractiveTools
|
|||
{
|
||||
Message = "Select a priority level:",
|
||||
RequestedSchema = prioritySchema
|
||||
}, token);
|
||||
}, cancellationToken);
|
||||
|
||||
if (priorityResponse.Action != "accept")
|
||||
{
|
||||
|
|
@ -184,7 +184,7 @@ public sealed class InteractiveTools
|
|||
{
|
||||
Message = "Select the issue severity:",
|
||||
RequestedSchema = severitySchema
|
||||
}, token);
|
||||
}, cancellationToken);
|
||||
|
||||
if (severityResponse.Action != "accept")
|
||||
{
|
||||
|
|
@ -218,7 +218,7 @@ public sealed class InteractiveTools
|
|||
{
|
||||
Message = "Select up to 3 tags:",
|
||||
RequestedSchema = tagsSchema
|
||||
}, token);
|
||||
}, cancellationToken);
|
||||
|
||||
if (tagsResponse.Action != "accept")
|
||||
{
|
||||
|
|
@ -257,7 +257,7 @@ public sealed class InteractiveTools
|
|||
{
|
||||
Message = "Select desired features:",
|
||||
RequestedSchema = featuresSchema
|
||||
}, token);
|
||||
}, cancellationToken);
|
||||
|
||||
if (featuresResponse.Action != "accept")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ Clients should check if the server supports logging by checking the <xref:ModelC
|
|||
[!code-csharp[](samples/client/Program.cs?name=snippet_LoggingCapabilities)]
|
||||
|
||||
If the server supports logging, the client should set the level of log messages it wishes to receive with
|
||||
the <xref:ModelContextProtocol.Client.McpClient.SetLoggingLevel*> method on <xref:ModelContextProtocol.Client.McpClient>. If the client does not set a logging level, the server might choose
|
||||
the <xref:ModelContextProtocol.Client.McpClient.SetLoggingLevelAsync*> method on <xref:ModelContextProtocol.Client.McpClient>. If the client does not set a logging level, the server might choose
|
||||
to send all log messages or none—this is not specified in the protocol. So it's important that the client
|
||||
sets a logging level to ensure it receives the desired log messages and only those messages.
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ if (firstArgument is not null)
|
|||
if (Enum.TryParse<LoggingLevel>(firstArgument, true, out var loggingLevel))
|
||||
{
|
||||
// <snippet_LoggingLevel>
|
||||
await mcpClient.SetLoggingLevel(loggingLevel);
|
||||
await mcpClient.SetLoggingLevelAsync(loggingLevel);
|
||||
// </snippet_LoggingLevel>
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue