mcp-client
MCP server from wangliguang/mcp-client-server
claude mcp add --transport stdio wangliguang-mcp-client-server node index.js \ --env ENV="环境变量示例,按需设置,例如 OPENAI_API_KEY、TOKEN 等"
How to use
mcp-client 是一个本地化的 MCP 服务客户端示例,主要通过 stdio 方式自带一个自定义的 MCP 服务器实现来与大模型进行对话并通过工具、资源等进行交互。你可以在根目录使用 npm run start 启动对话服务,并在 src/index 里选择要测试的 MCP 类型(如 stdio/compute、stdio/filesystem、streamable-http 等)。该项目提供了多种传输与对接方案,适合演示如何把大模型调用、工具调用和资源访问封装成 MCP 客户端/服务器对话流程。你可以通过工具接口(listTools、callTool)、资源接口(listResources、readResource)等与 MCP 服务交互,并可通过 _meta 字段传递上下文信息如 newsId 等来追踪会话上下文。
在使用时,默认使用本地 STDIO 服务器进行测试(通过 index.js 入口选择具体实现),也可切换到 sse 或 streamable-http 主题的实现以了解不同传输层的行为。通过 npm run sse 可以基于 stdio 启动 sse 服务,通过 npm run inspector 可以打开可视化测试工具。
How to install
安装步骤(适用于常见 Node.js 环境):
- 先安装 Node.js 与 npm:请确保系统已安装 Node.js(推荐版本与项目要求匹配)。
- macOS/Linux: 安装 n 或 nvm 后安装 Node.js。
- Windows: 使用 Node.js 官方安装包。
- 克隆或下载本仓库并进入目录:
- git clone <仓库地址>
- cd wangliguang-mcp-client-server
- 安装依赖:
- npm install
- 配置环境变量(可选但推荐):在根目录创建或更新 .env 文件,按照需要设置 OPENAI_API_KEY、TOKEN 等环境变量。
- 启动对话服务:
- npm run start
- 启动 sse 服务(用于测试 stdio 转换成 streamable-http 的场景):
- npm run sse
- 启动可视化测试工具( inspector):
- npm run inspector
说明:README 中提到的工具接口包括 listTools、callTool、listResources、readResource 等,使用时可通过 _meta 字段传递上下文信息来帮助调试与追踪。
Additional notes
实用提示与常见问题:
- 不同 MCP 客户端与服务器版本可能导致 protocol version not supported 错误,请确保 @modelcontextprotocol/sdk 的版本与服务端兼容,必要时升级或降级版本。
- stdio、sse、streamable-http 的选择取决于部署场景:stdio 适合本地开发与测试,sse 适合服务端环境,streamable-http 适合需要通过 HTTP 流的场景。
- 通过 requestInit 的 headers 可以注入鉴权 token 等信息,这在与大模型提供商接口打交道时很实用: new StreamableHTTPClientTransport(new URL('http://localhost:8000/sse'), { requestInit: { headers: { "Authorization": "Bearer xxx" } } })
- 使用 _meta 可以在调用工具、读取资源等接口时携带额外的上下文信息,如 newsId,用于调试和追踪特定会话。
- 本项目的示例服务器实现包含 stdio/compute/server.js,您也可以通过 index.js 选择其它 MCP 服务实现进行实验。
- 若遇到网络或依赖问题,请确保本地网络正常并且依赖版本与 Node.js 版本兼容。
Related MCP Servers
zen
Selfhosted notes app. Single golang binary, notes stored as markdown within SQLite, full-text search, very low resource usage
MCP -Deepseek_R1
A Model Context Protocol (MCP) server implementation connecting Claude Desktop with DeepSeek's language models (R1/V3)
mcp-fhir
A Model Context Protocol implementation for FHIR
mcp
Inkdrop Model Context Protocol Server
mcp-appium-gestures
This is a Model Context Protocol (MCP) server providing resources and tools for Appium mobile gestures using Actions API..
dubco -npm
The (Unofficial) dubco-mcp-server enables AI assistants to manage Dub.co short links via the Model Context Protocol. It provides three MCP tools: create_link for generating new short URLs, update_link for modifying existing links, and delete_link for removing short links.