AI

💻 MCP - Model Context Protocol

MCP

Model Context Protocol, 即模型上下文协议,是Anthropic提出的一个协议,用于在模型之间传递上下文信息。

What is MCP?
MCP is an open protocol that standardizes how applications provide context to LLMs.
Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories,
MCP provides a standardized way to connect AI models to different data sources and tools.

Why MCP?
MCP helps you build agents and complex workflows on top of LLMs. LLMs frequently need to integrate with data and tools, and MCP provides:

  • A growing list of pre-built integrations that your LLM can directly plug into
  • The flexibility to switch between LLM providers and vendors
  • Best practices for securing your data within your infrastructure

架构:→ client-server CS架构

  • MCP Hosts Programs like Claude Desktop, IDEs, or AI tools that want to access data through MCP
  • MCP Clients Protocol clients that maintain 1:1 connections with servers
  • MCP Servers Lightweight programs that each expose specific capabilities through the standardized Model Context Protocol
  • Local Data Sources Your computer’s files, databases, and services that MCP servers can securely access
  • Remote Services External systems available over the internet (e.g., through APIs) that MCP servers can connect to
  • 架构图
mcp-architecture


MCP Server: Core MCP Concepts

  • Resources: File-like data that can be read by clients (like API responses or file contents)
    文件类型的数据,可以被客户端读取(如API响应或文件内容)
  • Tools: Functions that can be called by the LLM (with user approval)
    可以被LLM调用的函数(需要用户批准)
  • Prompts: Pre-written templates that help users accomplish specific tasks
    预先编写的模板,帮助用户完成特定任务

Cursor中集成MCP

Demo: cursor-mcp-01

VSCode中集成MCP

cline

MCP Server

下面server按照首字母进行排序。

amap maps

Amap Maps MCP Server(MCP.so)

作用:高德地图
要付费,暂不使用..囧😶

fetch

作用:从互联网获取信息(网页内容抓取与格式转换)

Fetch MCP Server

1、使用dockerfile构建

$ cd /servers/src/fetch
$ docker build -t mcp/fetch -f Dockerfile .

2、客户端配置

"mcpServers": {
  "fetch": {
    "command": "docker",
    "args": ["run", "-i", "--rm", "mcp/fetch"]
  }
}

3、使用Demo mcp-server-fetch-01

4、tools
这里可以通过源码,查看具体实现的逻辑。 mcp-server-fetch-tools

filesystem

作用:访问本地文件系统

Filesystem MCP Server

1、使用dockerfile构建

$ docker build -t mcp/filesystem -f src/filesystem/Dockerfile .

2、客户端配置:使用docker实际上就是把本地的文件系统挂载到容器中

{
  "mcpServers": {
    "filesystem": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--mount", "type=bind,src=/Users/raywong/Desktop,dst=/projects/Desktop",
        "--mount", "type=bind,src=/Users/raywong/Documents,dst=/projects/Documents,ro",
        "mcp/filesystem",
        "/projects"cp
      ]
    }
  }
}

3、使用Demo mcp-server-filesystem-01

4、tools
这里可以通过源码,查看具体实现的逻辑。 mcp-server-filesystem-tools

github

作用:访问github上的信息

Github MCP Server

1、使用Dockerfile构建

$ docker build -t mcp/github -f src/github/Dockerfile . 

2、客户端配置 如下是在Cursor中配置(实际上就是启动mcp/github容器)。
注意: 在github中获取personal access token

{
  "mcpServers": {
    "github": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "mcp/github"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your github personal access token"
      }
    }
  }
}

3、使用Demo mcp-server-github-01

4、tools
这里可以通过源码,查看具体实现的逻辑。 mcp-server-github-tools

hotnews

1、使用dockerfile构建

$ docker build -t mcp/hotnews -f Dockerfile .

2、客户端配置

{
  "mcpServers": {
    "mcp-server-hotnews": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "wopal/mcp-server-hotnews"
      ]
    }
  }
}

3、使用Demo mcp-server-hotnews-01

4、tools
这里可以通过源码,查看具体实现的逻辑。 mcp-server-hotnews-tools

Reference

1. Model Context Protocol Official Document
2. Model Context Protocol Servers
3. Smithery
4. MCP.so