The SimpleClient project demonstrates how to connect to an MCP server using the Mcp.Net.Client
SDK. It showcases both transports (SSE and stdio), OAuth flows, resource/prompt discovery, and
now the elicitation and completion features introduced in the 2025-06-18 specification.
-
Start the sample server in one terminal:
dotnet run --project ../Mcp.Net.Examples.SimpleServer/Mcp.Net.Examples.SimpleServer.csproj
-
In another terminal, launch the client:
# SSE transport with dynamic registration + PKCE dotnet run -- --url http://localhost:5000 --auth-mode pkce # or stdio transport (starts the server as a child process) dotnet run -- --command "dotnet run --project ../Mcp.Net.Examples.SimpleServer -- --stdio"
The first connection performs capability negotiation, lists prompts/resources, and exercises the calculator and Warhammer tools. During the Warhammer demo you will be prompted with an elicitation request, and the completions section demonstrates how prompt arguments receive suggestions.
When the server calls elicitation/create, the client surfaces a console wizard:
=== Elicitation Request ===
Customize the inquisitor's profile or leave fields empty to keep the generated values.
Choose action ([A]ccept / [D]ecline / [C]ancel):
Acceptwalks through each schema property, validating types (integers, booleans, enums, etc.). Leaving a field blank keeps the server-generated value.Declinecompletes the prompt without sending overrides.Cancelaborts the request (the server will treat it as a user cancellation).
The handler lives in Elicitation/ConsoleElicitationHandler.cs and demonstrates:
- Reading the incoming
ElicitationRequestContext(message, schema, raw JSON). - Prompting for each schema-defined field.
- Validating numeric ranges, enum selections, and booleans.
- Returning
ElicitationClientResponse.Accept/Decline/Cancel.
Both SSE and stdio demos register the handler via McpClientBuilder.WithElicitationHandler(...)
or client.SetElicitationHandler(...). The client only advertises the elicitation capability
when a handler is registered, so call one of these before Initialize.
After prompts are listed the sample requests suggestions for the
draft-follow-up-email prompt:
- Typing
engfor therecipientargument returns team aliases seeded by the server - Providing the recipient and requesting completions for
contextsurfaces helpful phrasing hints
Both SSE and stdio demos use the new IMcpClient.CompleteAsync helper. The client only calls
completion/complete when the server advertises the capability negotiated during initialization.
--auth-mode pkce(default) uses demo OAuth configuration with dynamic registration.--auth-mode clientperforms a client-credentials exchange.--auth-mode nonedisables bearer tokens.
See Authorization folder for the PKCE helper logic and Mcp.Net.Examples.Shared for shared
constants.
-
Swap
ConsoleElicitationHandlerwith your UI implementation (WinUI, WPF, web). -
Use the builder helpers in your own clients:
var client = new McpClientBuilder() .UseSseTransport(serverUrl) .WithElicitationHandler(async (ctx, ct) => { // Render your UI here return ElicitationClientResponse.Decline(); }) .Build(); await client.Initialize();
-
Explore the server project to see how tools request elicitation (
Warhammer40kTools).