Multi-Protocol MCP Server
A framework that supports stdio, streamable HTTP, and SSE protocols for MCP services, enabling one-time development for multiple platforms.
README
一个同时支持stdio,streamableHttpless和sse三种协议的MCP服务框架
项目说明
目前MCP服务在AI方向的业务使用频率很高,但随着业务的加深,发现存在以下痛点: 1.不同平台对MCP服务协议要求不同,有支持streamableHttp,有仅支持sse的。相同功能重复开发,浪费时间成本 2.有些研发人员并不了解MCP,现学现开发会让研发周期加长,时间成本耗费过多 为了解决不同平台不同要求,降低研发人员开发成本,本人提出一个框架,同时支持stdio,streamableHttpless和sse三种模式,实现一次开发实现三种模式
目录结构
- build: 编译之后的文件
- src
-- router: 配置streamableHttp和sse协议的路由
-- index.ts: 注册streamableHttp路由入口
-- mcp.ts: streamableHttp的配置路径,具体为
process.env.MCP_BASE_PATH的路径请求,如果没有配置,默认/mcp -- sse.ts: sse的配置路径,具体为process.env.MCP_BASE_PATH的路径请求,如果没有配置,默认/mcp -- tools: mcp的工具 -- index.ts: 注册工具 -- mockFunc.ts: 模拟一个工具写法 - 这部分需要根据业务开发 -- cli.ts: 命令行解析工具 -- index.ts: 总入口 -- server.ts: 创建Mcp服务 -- sse.ts: 运行sse模式 -- stdio.ts: 运行stdio模式 -- streamableHttp.ts: 运行streamableHttp模式 - xingyun/bin : 是根据我们业务使用的部署工具开发的部署脚本 - 这部分需要根据实际部署平台更改
- build_xingyun.sh: 是根据我们业务使用的部署工具开发的部署脚本 - 这部分需要根据实际部署平台更改
启动服务
1.启动stdio: npm run start 是默认启动stdio
1.启动StreamableHttp: npm run start:http 是默认启动端口3001
2.更改端口启动StreamableHttp: npm run dev:http 或者 npm run start -- -t http -p 3001 -t httt: 代表启动StreamableHttp -p 3001: 代表启动端口3001
测试StreamableHttp方式
第一种方式 curl命令
1.cd demo && npm run dev:http // 这个会启动 http://localhost:3001/mcp 这个地址 2.终端curl命令
curl -X POST http://localhost:3001/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "mockfunc",
"arguments": {"desc": "测试参数","desc1": "测试参数"
}
},
"id": 1
}'
第二种方式 使用inspector工具
1.cd demo && npm run dev:http // 先启动自己服务 2.npm run inspector // 启动inspector工具 3.在URL地址配上自己服务地址
测试SSE方式
方式和测试StreamableHttp方式 相同,只不过启动是用 npm run start:sse
环境变量说明
内网使用配置
环境变量配置
# 监听特定内网IP(例如:192.168.1.100)
export MCP_HOST=192.168.1.100
export MCP_PORT=3001
# 使用内网域名(可选)
export MCP_DOMAIN=mcp-server.internal.com
# 修改基础路径(可选,默认是 /mcp)
export MCP_BASE_PATH=/api/mcp
端口配置优先级
- 环境变量
MCP_PORT(最高优先级) - 命令行参数
--port - 默认值:3001端口
访问地址优先级
- 环境变量
MCP_DOMAIN(最高优先级) - 环境变量
MCP_HOST - 默认: localhost
内网访问方式
假设你的内网服务器IP是 192.168.1.100,端口是 3001:
基础访问:
http://192.168.1.100:3001/sales
带域名的访问:
http://mcp-server.internal.com/sales
自定义路径:
http://192.168.1.100:3001/api/mcp
额外说明
1.在 xingyun/bin/control.sh中,这段代码是启动streamableHttpless的,如果需要启动sse,需要改为 npm run start:sse
start(){
npm run start:http
sleep 3
status
}
2.在package.json中 stop的语句是 "stop": "pkill -f \"demo\" || true",这个demo是要根据你自己启动服务的名字相同
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.