背景
因为claude code 的官方文档Model Context Protocol (MCP) - Anthropic使用mcp的介绍没有示例,
本文档以两个mcp示例来指导如何使用:
在MCP 广场 · 魔搭社区上有很多可用的mcp
先上示例
basic-memory
说明
记忆知识库 · MCP
在快速开始的有安装指导
# Install with uv (recommended)
uv tool install basic-memory# Configure Claude Desktop (edit ~/Library/Application Support/Claude/claude_desktop_config.json)
# Add this to your config:
{"mcpServers": {"basic-memory": {"command": "uvx","args": ["basic-memory","mcp"]}}
}
# Now in Claude Desktop, you can:
# - Write notes with "Create a note about coffee brewing methods"
# - Read notes with "What do I know about pour over coffee?"
# - Search with "Find information about Ethiopian beans"
使用方法:
-
在服务器上安装uv
pip install uv
-
使用uv安装basic-memory
uv tool install basic-memory uv tool list
-
添加basic-memory到claude code 项目中
# 新建项目 mkdir test && cd test # 添加project scope的 mcp,别的项目不受影响, -s user 是添加用户级别, claude mcp add-json basic-memory '{"type":"stdio","command":"uvx","args":["basic-memory","mcp"],"env":{}}' -s project
添加后,可在项目根目录看到.mcp.json文件
-
claude code 使用basic-memory效果
#启动claude 后 /mcp 可以看见mcp服务的状态 #对话使用示例,以正在开发的服务
以下是在使用claude过程中自动记录
新开会话,让claude code读取之前的工作
或者恢复之前的上下文
效果总结:
相当于给claude code做了一记事本, 可以方便的查询之前已经做的工作,或者在第二天工作时继续 昨天的工作
postgre
下面介绍另一个方便的工具PostgreSQL模型上下文协议服务器 · MCP
-
下载docker image
docker pull mcp/postgres
-
填写连接信息
直接在项目根目录下新建.mcp.json,内容如下
{"mcpServers": {"basic-memory": {"type": "stdio","command": "uvx","args": ["basic-memory","mcp"],"env": {}},"postgres": {"type": "stdio","command": "docker","args": ["run","-i","--rm","--network=host","mcp/postgres","postgresql://postgres:postgres%40cloud@localhost:18101/cloud-platform"],"env": {}}} }
-
claude code使用情况
可以直接查库,比较方便
使用效果总结
当数据库中新增表,或者表字段发生变更时,可以让claude code 快速查库,以更新代码
以上两个示例都 是使用本地部署的mcp服务,("type": "stdio")
实际上如果我们的claude code可以连网,可以直接使用modelscope提供的sse服务 ,将mcp服务部署在阿里云上(白嫖),一键生成mcp的url,直接使用,下面以figma为例说明
figma(SSE)
在魔塔社区Figma · MCP上使用figma的apikey,可以直接生成一个sse类型的mcp服务
将这个json填入.mcp.json中,就可以了!很简单
以下是claude code 使用figma mcp生成前台页面的效果:
只能说是一毛一样!
但是使用魔塔社区的SSE方式的figma mcp无法将图片下载到本地,实际下载进魔塔服务器了,以下是使用stdio方式使用方法:
{"mcpServers": {"Framelink Figma MCP": {"timeout": 60,"type": "stdio","command": "npx","args": ["-y","figma-developer-mcp","--figma-api-key=your-api-key","--stdio"]}}
}
需要本地有npm和npx包
附:figma api key获取指导
1. Grab your Figma access token
Before you can make requests to the Framelink Figma MCP server, you will need to generate a Figma access token.
- From the home page in Figma, click your profile icon in the top left corner and select
Settings
from the dropdown. - In the settings menu, select the
Security
tab. - Scroll down to the
Personal access tokens
section and clickGenerate new token
. - Enter a name for the token and make sure you have read permissions on File content and Dev resources, then click
Generate token
.