Mcp 标志

Mcp

组织
managedcode
mcp

Build or consume Model Context Protocol (MCP) servers and clients in .NET using the official MCP C# SDK, including stdio, Streamable HTTP, tools, prompts, resources, and capability negotiation. USE FOR: .NET MCP servers or clients; stdio versus HTTP transport choices; tools, resources, prompts, completions, and capability negotiation. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.

概览

发布者managedcode
代码仓库dotnet-skills
技能名称mcp
星标数
492
复刻数
38
附带文件
3
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载的 SKILL.md 文件,因此只有在请求确实匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 3 个随附文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 managedcode 发布于 GitHub。请在安装前查看源内容。

安装

在 TypingMind 中安装 Mcp AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/managedcode/dotnet-skills/tree/main/catalog/Libraries/MCP/skills/mcp
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/managedcode/dotnet-skills.git /tmp/dotnet-skills
mkdir -p .claude/skills
cp -r /tmp/dotnet-skills/catalog/Libraries/MCP/skills/mcp .claude/skills/mcp
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Mcp,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Mcp。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Mcp 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会获取指令,因此未使用的技能不会产生额外费用。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

MCP C# SDK for .NET

Trigger On

  • building or consuming MCP servers from a .NET application or library
  • choosing between stdio and HTTP transport for MCP
  • exposing tools, resources, prompts, completions, or logging to an MCP host
  • connecting a .NET app to an existing MCP server and passing discovered tools into IChatClient
  • bootstrapping a minimal MCP client/server from the .NET AI quickstarts or publishing a server to the MCP Registry
  • implementing capability-aware flows such as roots, sampling, elicitation, subscriptions, session resumption, or enterprise managed authorization

Use This Skill Instead Of

  • Use mcp when protocol interoperability is the requirement.
  • Use microsoft-extensions-ai when you only need model/provider abstraction or local tool orchestration without the MCP wire protocol.
  • Use microsoft-agent-framework when the main problem is agent orchestration; combine it with mcp only when those agents must consume or expose MCP endpoints.
  • Use the .NET AI quickstarts for the very first vertical slice, then come back here to harden transport, capability negotiation, publishing, and host interoperability.

Documentation

References

Load only what the task needs:

  • references/patterns.md - current server/client patterns, transports, capabilities, filters, and chat-client integration
  • references/security.md - safe error handling, auth boundaries, stdio logging hygiene, and defensive tool/resource patterns

Package Selection

PackageChoose when
ModelContextProtocol.CoreYou only need a client or low-level server APIs and want the smallest dependency set.
ModelContextProtocolYou want the main SDK package with hosting, DI, attribute discovery, and stdio server support. Start here for most projects.
ModelContextProtocol.AspNetCoreYou are hosting a remote MCP server in ASP.NET Core over HTTP. This includes the main package.

Transport Selection

TransportUse whenNotes
StdioClientTransport / WithStdioServerTransport()The MCP server should run as a local child process.Best for local tooling and editor/agent integrations.
HttpClientTransport + HttpTransportMode.StreamableHttpThe server is remote or should be reachable over HTTP.Recommended HTTP transport; supports streaming and session resumption.
HttpTransportMode.SseYou must connect to an older SSE-only server.Legacy compatibility only; do not choose this for new servers.

Current v2.2 Notes

  • The August 2026 .NET AI MCP documentation separates a getting-started hub, client and server quickstarts, MCP Registry publishing, and a server-resource index. Use those pages to bootstrap a vertical slice, then return to the C# SDK docs here for exact transport, capability, authorization, and lifecycle behavior.
  • SDK v2.0.0 aligns with MCP 2026-07-28: HTTP is stateless by default, clients negotiate with server/discover before falling back to legacy initialize, Tasks move to ModelContextProtocol.Extensions.Tasks, and Roots, Sampling, and Logging are deprecated for the new protocol. Set HttpServerTransportOptions.Stateless = false only for an intentional stateful compatibility requirement.
  • SDK v2.1.0 adds an opt-in subscriptions/listen server handler, keeps AutoDetect usable after a provisional SSE failure, preserves HTTP status codes across target frameworks, and falls back to initialize when server/discover fails at the HTTP layer. Add custom notification streams only when both peers negotiate the extension.
  • SDK v2.2.0 adds HttpServerSessionMode so one ASP.NET Core endpoint can serve stateful and stateless clients across the MCP 2025-11-25 and 2026-07-28 protocol versions. Choose the mode explicitly, test both negotiated paths when compatibility matters, and upgrade before working around malformed percent-encoded request headers because the release fixes that decoding failure.
  • Before moving from v1.4.x, update structured-result consumers to accept non-object values directly, require Tool.inputSchema in custom payloads, move Tasks to the extension package, and test PKCE S256 plus issuer validation in OAuth metadata.
  • Enterprise managed authorization now has an SDK surface through IdentityAssertionGrantProvider for the Identity Assertion Authorization Grant flow. Use it only when the enterprise SSO and MCP authorization-server contract is part of the actual scenario.
  • StdioClientTransportOptions.InheritEnvironmentVariables controls whether child-process MCP servers inherit the parent environment. Set it intentionally when launching untrusted or third-party servers.
  • Streamable HTTP session DELETE is hardened to require the same authenticated user that opened the session. Do not build custom session cleanup paths that bypass that authorization check.
  • Stdio transport no longer logs child-process environment variables at trace level, but server authors should still treat environment variables as secrets.

Workflow

  1. Pick the package and transport first.

    • Local child-process server: ModelContextProtocol + WithStdioServerTransport().
    • Remote server: ModelContextProtocol.AspNetCore + WithHttpTransport() + MapMcp().
    • Client-only app: start with ModelContextProtocol or ModelContextProtocol.Core.
    • Registry distribution: pair a minimal server with the MCP Registry publishing flow only after the server contract is stable.
  2. Model the MCP surface explicitly.

    • Tools: [McpServerToolType] + [McpServerTool]
    • Resources: [McpServerResourceType] + [McpServerResource]
    • Prompts: [McpServerPromptType] + [McpServerPrompt]
    • Use custom handlers or filters only for cross-cutting behavior, protocol extensions, or advanced routing.
  3. Prefer attribute discovery for straightforward servers.

csharp
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
using System.ComponentModel;

var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole(options =>
{
    options.LogToStandardErrorThreshold = LogLevel.Trace;
});

builder.Services
    .AddMcpServer()
    .WithStdioServerTransport()
    .WithToolsFromAssembly();

await builder.Build().RunAsync();

[McpServerToolType]
public static class EchoTool
{
    [McpServerTool, Description("Echoes the message back to the client.")]
    public static string Echo(string message) => $"hello {message}";
}
  1. For HTTP servers, use the ASP.NET Core transport and map the endpoint directly.
csharp
using ModelContextProtocol.Server;
using System.ComponentModel;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddMcpServer()
    .WithHttpTransport()
    .WithToolsFromAssembly();

var app = builder.Build();
app.MapMcp("/mcp");
app.Run();

[McpServerToolType]
public static class EchoTool
{
    [McpServerTool, Description("Echoes the message back to the client.")]
    public static string Echo(string message) => $"hello {message}";
}
  1. When consuming a server, use McpClient.CreateAsync(...) and stay capability-aware.
csharp
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;

var transport = new StdioClientTransport(new StdioClientTransportOptions
{
    Name = "Everything",
    Command = "npx",
    Arguments = ["-y", "@modelcontextprotocol/server-everything"],
});

await using var client = await McpClient.CreateAsync(transport);

IList<McpClientTool> tools = await client.ListToolsAsync();

if (client.ServerCapabilities.Prompts is not null)
{
    var prompts = await client.ListPromptsAsync();
}
  1. Treat optional features as negotiated capabilities, not assumptions.

    • Client capabilities: configure McpClientOptions.Capabilities for roots, sampling, and elicitation.
    • Server capabilities are inferred from registered features.
    • Check client.ServerCapabilities before using completions, logging, prompt list-change notifications, or resource subscriptions.
    • Use client.NegotiatedProtocolVersion or server.NegotiatedProtocolVersion only when version-specific behavior matters.
  2. Keep HTTP guidance current.

    • Streamable HTTP is the recommended transport for remote servers.
    • MapMcp() also serves SSE compatibility endpoints for older clients.
    • HTTP clients can use AutoDetect by default, or force StreamableHttp / Sse.
    • Session resumption is available for Streamable HTTP through McpClient.ResumeSessionAsync(...).
    • For authenticated Streamable HTTP sessions, cleanup and resume operations must preserve the same user boundary.
  3. Treat the .NET AI MCP quickstarts as bootstrap examples.

    • build-mcp-client and build-mcp-server are good starting points when the surrounding app is still MEAI-centric.
    • publish-mcp-registry is the distribution step, not the design step. Stabilize the protocol surface before publishing.
  4. Respect current error and serialization rules.

    • Tool exceptions normally come back as CallToolResult.IsError == true.
    • Throw McpProtocolException only for protocol-level JSON-RPC failures.
    • McpClientTool inherits from AIFunction, so discovered tools can be passed directly into IChatClient.
    • Experimental APIs use MCPEXP... diagnostics; suppress them intentionally, not globally by accident.
    • If you use a custom JsonSerializerContext, prepend McpJsonUtilities.DefaultOptions.TypeInfoResolver so MCP protocol types keep the SDK's contract.

Anti-Patterns To Avoid

Anti-patternWhy it causes troubleBetter approach
Picking HTTP transport for a purely local child-process scenarioAdds unnecessary hosting, auth, and deployment surfaceUse stdio for local/editor-hosted integrations
Treating SSE as the default remote transportLocks new work to legacy behaviorPrefer Streamable HTTP and keep SSE only for backward compatibility
Writing tools without [Description] metadataHosts and models lose schema clarityDescribe tool purpose and parameters explicitly
Returning huge binary/text payloads from every tool callBloats context and slows hostsReturn focused content and move large data to resources
Logging to stdout on stdio serversCorrupts the protocol streamSend logs to stderr
Assuming prompts/resources/logging/completions existBreaks against partial implementationsCheck negotiated capabilities first
Using filters for normal business logicMakes handlers opaque and hard to reason aboutKeep filters for cross-cutting policy, audit, or protocol plumbing

Deliver

  • a correctly packaged MCP server or client that matches the deployment topology
  • explicit tool/resource/prompt definitions with descriptions and bounded payloads
  • capability-aware handling for optional MCP features
  • validation notes for transport, auth boundary, and host/client interoperability

Validate

  • chosen package matches the topology: Core, ModelContextProtocol, or AspNetCore
  • stdio servers do not write logs or diagnostics to stdout
  • HTTP servers use MapMcp() and are tested at the final route, for example /mcp
  • tools, resources, and prompts use current [McpServer*] attributes or documented handler/filter alternatives
  • client code checks ServerCapabilities before using subscriptions, completions, logging, or prompt/resource list-change flows
  • Streamable HTTP is the default for new remote servers; SSE is used only for legacy compatibility
  • experimental APIs and custom serialization settings are reviewed intentionally rather than copied blindly

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Mcp AI 技能有什么作用?

Build or consume Model Context Protocol (MCP) servers and clients in .NET using the official MCP C# SDK, including stdio, Streamable HTTP, tools, prompts, resources, and capability negotiation. USE FOR: .NET MCP servers or clients; stdio versus HTTP transport choices; tools, resources, prompts, completions, and capability negotiation. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.

为什么在 TypingMind 中使用 Mcp?

因为您只需安装一次,就能搭配任何模型使用。Mcp 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型,甚至可以在聊天中途切换模型,而不会影响技能正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Mcp?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/managedcode/dotnet-skills/tree/main/catalog/Libraries/MCP/skills/mcp。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Mcp?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Mcp 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以搭配 Mcp 使用,包括 GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等,都可在 TypingMind 中使用您自己的 API 密钥接入。

Mcp AI 技能免费吗?

是的。该技能源自 managedcode 在 GitHub 上以 MIT 许可证发布的项目。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇