LA

lirantal/awesome-mcp-best-practices

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

86 stars 10 forks 质量 76 趋势 14Apache-2.0

lirantal/awesome-mcp-best-practices 是从 https://github.com/lirantal/awesome-mcp-best-practices. 导入的 MCP 服务器候选

概览

lirantal/awesome-mcp-best-practices 是从 https://github.com/lirantal/awesome-mcp-best-practices. 导入的 MCP 服务器候选

概述(AI 翻译)

一份经过精心策划且观点鲜明的模型上下文协议(MCP)最佳实践清单,介绍构建MCP服务器和MCP客户端。


MCP服务器

  • 1 MCP 服务器工具
  • 1.1 工具命名标准
  • 1.2 工具命名别名
  • 1.3 工具描述标准
  • 1.4 避免未找到的回答
  • 2 MCP服务器定义
  • 2.1 提供丰富的服务器指令
  • 3 MCP 服务器架构
  • 3.1 抽象服务器功能
  • 3.2 不要将1:1 API映射到工具
  • MCP服务器测试
  • MCP服务器部署
  • 将你的MCP服务器打包为Docker容器
  • MCP服务器安全
  • 安全MCP服务器代码
  • 安全MCP服务器依赖
  • 避免描述性错误
  • MCP服务器性能
  • 缓存昂贵的工具
  • MCP服务器错误与可观测性
  • 优雅的暂停

MCP客户

待定


1 MCP 服务器工具

🔵 1.1 工具命名标准

为您的 MCP 服务器 Tools 使用一致且兼容的命名规范,以确保 MCP 客户端能够正确发现并调用它们。

❌ 避免使用这些工具命名规范

  • 空格:get Npm Package Info
  • 点记法:get.Npm.Package.Info
  • 括号/括号:get(Npm)PackageInfo

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Awesome MCP Best Practices

A curated and opinionated list of awesome Model Context Protocol (MCP) best practices as they pertain to building MCP Servers and MCP Clients.


MCP Servers

MCP Clients

// TBD


1 MCP Server Tools

🔵 1.1 Tool Naming Standards

Use consistent, compatible naming conventions for your MCP Server Tools to ensure they can be properly discovered and invoked by MCP Clients.

❌ Avoid These Tool Naming Conventions

  • Spaces: get Npm Package Info
  • Dot notation: get.Npm.Package.Info
  • Brackets/parentheses: get(Npm)PackageInfo
  • ✅ camelCase (preferred): getNpmPackageInfo
  • kebab-case: get-npm-package-info
  • snake_case: get_npm_package_info
server.tool(
  "getNpmPackageInfo",
  "Get information about an npm package",
  {
    packageName: z.string()
  },
  async ({ packageName }) => {    
    // Implementation details...
    return {
      content: [{ type: "text", text: output }],
    };
  }
);

💡 Why It Matters

Using non-standard naming conventions can prevent or disrupt MCP Clients from properly discovering and surfacing your tools to end users. GPT-4o tokenization works best with camelCase naming conventions.


🔵 1.2 Tool Naming Aliases

When the Tool name can be intereted and accessed using different naming conventions, call out aliases in the Tool’s description.

❌ Problematic Pattern

For example, a postMesage tool name might be too specific:

server.tool(
  "postMessage",
  "Post a message under your account",
   () => {}
)

The LLM might not invoke the tool if the users ask for “share a social post on Twitter”, or “upload this picture to Instagram”.

Specify aliases and elaborate description for LLMs to better understand when it is required to invoke your tool.

server.tool(
  "postMessage",
  "Upload, share, and post messages on social media",
   () => {}
)

在 GitHub 查看完整 README

安装

docker run -p 3000:3000 your-mcp-server-image
新手?先看 mcpskill.org 教程 →