MCP Servers

A collection of Model Context Protocol servers, templates, tools and more.

一个同时支持stdio,streamableHttp和sse的mcp框架,ts语言的

Created 12/16/2025
Updated about 11 hours ago
Repository documentation and setup instructions

一个同时支持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

端口配置优先级

  1. 环境变量 MCP_PORT(最高优先级)
  2. 命令行参数 --port
  3. 默认值:3001端口

访问地址优先级

  1. 环境变量 MCP_DOMAIN(最高优先级)
  2. 环境变量 MCP_HOST
  3. 默认: 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是要根据你自己启动服务的名字相同

Quick Setup
Installation guide for this server

Install Package (if required)

npx @modelcontextprotocol/server-mcp-server-ts

Cursor configuration (mcp.json)

{ "mcpServers": { "xingtongcai-mcp-server-ts": { "command": "npx", "args": [ "xingtongcai-mcp-server-ts" ] } } }