48 CZ-PRG (GMT+1)
US-NYC (GMT-5)
Blazor Web App (Server rendered)
AI AGENTS · INTEROPERABLE TOOLS

MCP Connectors

The Model Context Protocol (MCP) gives AI applications a standard way to discover and call tools exposed by independent servers. This guide explains MCP in .NET and includes a working client restricted to allowlisted, read-only public repository tools—plus a clear path for optional, OAuth-protected Gmail access.

Public-data demo; private connectors need consent

DeepWiki is selected by default and can inspect public repository documentation without a login. The application passes only three explicitly allowlisted, read-only wiki tools to the model. Tool results are sent to the configured chat provider. Never put passwords, API keys, private email, or confidential prompts into a public connector. Gmail is unchecked by default because access requires explicit Google OAuth consent; this sample does not collect Google passwords or tokens.

THE PROTOCOL AT A GLANCE

A standard boundary between an AI host and tools

MCP standardizes the conversation between a host application and a connector server. The host owns the user experience and policy; an MCP client manages a protocol session; the server advertises capabilities and performs only the operations that its implementation allows. MCP uses JSON-RPC messages, capability negotiation, and typed schemas rather than asking a model to execute arbitrary code.

CapabilityWhat the server offersTypical use
Tools Named operations with JSON input schemas and structured results. Search a public repository, retrieve a forecast, or perform a narrow action.
Resources Addressable context that a client can list or read. Documentation pages, records, or files authorized for the current user.
Prompts Reusable prompt templates supplied by a server. Standardized workflows that the user can choose and review.
Sampling and elicitation Optional server-to-client requests for model work or user input. Advanced integrations that require explicit host policy and consent.
1 · CONNECT

Negotiate a session

The client selects a transport, initializes the protocol, and checks server capabilities.

2 · DISCOVER

Inspect available tools

The host reviews each tool name, description, and schema before exposing it to a model.

3 · AUTHORIZE + CALL

Keep control in the host

The host decides which tool calls are permitted, forwards the result, and closes the session.

.NET AND NUGET

The official C# SDK and common transports

PackagePurposeWhen to choose it
ModelContextProtocol Official .NET MCP client and server SDK, with hosting and dependency-injection support. Most .NET applications connecting to MCP servers or hosting stdio servers. This page uses version 2.3.0.
ModelContextProtocol.Core Lower-level client and server APIs with fewer hosting dependencies. Libraries that need the protocol primitives but provide their own application composition.
ModelContextProtocol.AspNetCore ASP.NET Core transport and endpoint helpers for hosting an HTTP MCP server. Expose application-owned tools over Streamable HTTP. Restrict hosts, authentication, and CORS.
Microsoft.Extensions.AI Provider-neutral chat abstractions, including IChatClient, ChatOptions, and function invocation. Pass discovered MCP tools to a supported .NET chat client as AIFunction instances.
Microsoft.Extensions.AI.OpenAI, Anthropic, Google.GenAI Provider adapters used by the existing AI Agent settings and playgrounds. Use the provider configured in AI Agent Settings; tool calling support varies by provider and model.

Connect to the no-login DeepWiki MCP server

DeepWiki exposes public repository documentation tools without a login. The server may advertise additional OAuth-protected operations, so this sample explicitly allowlists only its three read-only wiki tools. It uses the recommended Streamable HTTP endpoint and a fixed HTTPS host; it does not accept a URL from the user or from the model.

using Microsoft.Extensions.AI;
using ModelContextProtocol.Client;

var transport = new HttpClientTransport(new HttpClientTransportOptions
{
    Endpoint = new Uri("https://mcp.deepwiki.com/mcp"),
    TransportMode = HttpTransportMode.StreamableHttp,
    ConnectionTimeout = TimeSpan.FromSeconds(15)
});

await using var mcpClient = await McpClient.CreateAsync(transport);
var discoveredTools = await mcpClient.ListToolsAsync();
var allowedToolNames = new HashSet<string>(StringComparer.Ordinal)
{
    "ask_wiki_question", "read_wiki_contents", "read_wiki_structure"
};
var tools = discoveredTools
    .Where(tool => allowedToolNames.Contains(tool.Name))
    .ToList();

using IChatClient toolClient = chatClient.AsBuilder()
    .UseFunctionInvocation(configure: options =>
    {
        options.MaximumIterationsPerRequest = 8;
        options.MaximumConsecutiveErrorsPerRequest = 1;
    })
    .Build();

var answer = await toolClient.GetResponseAsync(
    [new ChatMessage(ChatRole.User, "Explain the public repository's MCP client API.")],
    new ChatOptions { Tools = [.. tools] },
    cancellationToken);

stdio versus Streamable HTTP

TransportConnection modelImportant boundary
stdio The host launches a local child process and exchanges JSON-RPC over standard input/output. Do not launch arbitrary commands or inherit the web process's secrets into third-party child processes.
Streamable HTTP A client connects to a remote HTTPS endpoint; this is the recommended transport for remote MCP servers. Use an allowlist, short connection and request timeouts, appropriate authentication, and no model-controlled URLs.
SSE Legacy HTTP transport retained for older servers. Prefer Streamable HTTP for new integrations and follow the server's published transport support.
PRIVATE CONNECTORS

Gmail requires real Google OAuth

There is no legitimate login-free way to read a user's Gmail. A Gmail MCP server must be trusted and authenticated, and the user must authorize the requested Google scopes. For a read-only demo, request the narrow Gmail read-only scope rather than message-send or mailbox-modification permissions.

This playground includes Gmail as an unchecked connector choice so its consent boundary is visible, but it does not connect to Gmail because this application has no configured Google OAuth client or authenticated Gmail MCP endpoint. Selecting Gmail shows an explanation and prevents the public demo from running until that integration is properly configured.

// Obtain this token through a real Google OAuth authorization-code + PKCE flow
// with the user's consent and the narrow Gmail read-only scope.
var gmailTransport = new HttpClientTransport(new HttpClientTransportOptions
{
    Endpoint = new Uri("https://your-trusted-gmail-mcp.example/mcp"),
    TransportMode = HttpTransportMode.StreamableHttp,
    AdditionalHeaders = new Dictionary<string, string>
    {
        ["Authorization"] = $"Bearer {oauthAccessToken}"
    }
});

await using var gmailClient = await McpClient.CreateAsync(gmailTransport);
var gmailTools = await gmailClient.ListToolsAsync();

The endpoint and token above are placeholders, not a public Gmail service. Store OAuth tokens in a server-side token store, use per-user authorization, and never paste Google credentials into this page or commit them to source control.

HANDS-ON · LIVE MCP CLIENT

Connect selected MCP servers

Inspect the real tool catalog without an LLM, or send a Czech question through the selected public MCP tools and your configured .NET chat provider.

Data flow: The selected provider receives your question, selected tool schemas, and MCP results. DeepWiki receives only the arguments for a public repository tool call. Provider keys remain in browser settings until a request, are sent only to the selected official provider endpoint, and are never forwarded to DeepWiki.
Loading saved AI Agent settings…
Select connectors

Read-only tools for exploring public GitHub repository documentation. No login is required.

Google OAuth consent and a trusted Gmail MCP server are required. This demo does not collect Google passwords or tokens.

Use the owner/repository format, for example modelcontextprotocol/csharp-sdk.
The default question asks about the public .NET MCP SDK; keep private or confidential data out of public connector prompts.
SECURITY AND OPERATIONS

Treat every connector as a separate trust boundary

Review before exposing tools

An MCP server can return hostile descriptions or data. Allowlist server endpoints, inspect tool schemas, expose only selected tools, and treat every result as untrusted input.

Authorize outside the model

Tool descriptions do not grant permission. For Gmail, check the signed-in user, OAuth scopes, mailbox ownership, and approval for any write action in server code.

Bound calls and results

Use per-request timeouts, iteration limits, output-size caps, rate limits, and cancellation. The playground limits the automatic tool loop and uses a fixed public endpoint.

Choose least privilege

Prefer no-auth public data for experiments. For private data, use OAuth consent and narrow scopes; never place access tokens in prompts, source code, or browser-visible markup.

Read the MCP specification, the official C# SDK docs, and the DeepWiki MCP documentation. See Tools & Plugins for application-owned functions and API tools.

An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.