Token导航 LogoToken导航TokenDH.com
Mcpserverdemo logo
运维云端stdio官方级别未说明来源级核验

Mcpserverdemo

MCP Server

一个基于FastAPI和Python实现的JSON-RPC服务器,提供加法和乘法方法。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
PythonClaude本地部署JSON-RPCFastAPIClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

NitinUdasin

提供方

NitinUdasin

最后核验

2026/5/17 20:23

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

uv run python -m uvicorn main:app --reload

详细介绍

基于FastAPI和Python的JSON RPC服务器

该项目使用Python中的FastAPI、Uvicorn和jsonrpcserver实现了一个简单的JSON-RPC服务器。它暴露了 addmultiply 方法。

设置

  1. 克隆存储库:
   git clone 
   cd json-rpc-server
  1. 使用创建虚拟环境并安装依赖项 uv:
   uv venv
   .\.venv\Scripts\activate # On Windows
   # source .venv/bin/activate # On Linux/macOS
   uv pip install fastapi uvicorn jsonrpcserver

运行服务器

要使用自动重新加载启动开发服务器,请执行以下操作:

.\.venv\Scripts\activate # On Windows
# source .venv/bin/activate # On Linux/macOS
uv run python -m uvicorn main:app --reload

服务器将在以下时间运行 http://127.0.0.1:8000/.

API终点

得到/

一个简单的测试端点,用于确认服务器正在运行。

请求:

# Using curl (Linux/macOS/Git Bash)
curl http://127.0.0.1:8000/

# Using Invoke-RestMethod (PowerShell)
Invoke-RestMethod -Uri "http://127.0.0.1:8000/" -Method Get

答复:

{
  "message": "FastAPI is running!"
}

POST/(JSON-RPC 2.0)

这是JSON-RPC的主要端点 addmultiply 方法。

添加方法

请求:

# Using curl
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "add", "params": [2, 3], "id": 1}' http://127.0.0.1:8000/

# Using Invoke-RestMethod (PowerShell)
Invoke-RestMethod -Uri "http://127.0.0.1:8000/"   -Method Post -Headers @{ "Content-Type" = "application/json" }   -Body '{"jsonrpc":"2.0","method":"add","params":[2,3],"id":1}'

响应(示例):

{"jsonrpc": "2.0", "result": 5, "id": 1}

乘法

请求:

# Using curl
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "multiply", "params": [4, 5], "id": 1}' http://127.0.0.1:8000/

# Using Invoke-RestMethod (PowerShell)
Invoke-RestMethod -Uri "http://127.0.0.1:8000/"  -Method Post -Headers @{ "Content-Type" = "application/json" }  -Body '{"jsonrpc":"2.0","method":"multiply","params":[4,5],"id":1}'

响应(示例):

{"jsonrpc": "2.0", "result": 20, "id": 1}

信号调用中的乘法方法

curl -X POST -H "Content-Type: application/json" -d '[{"jsonrpc": "2.0", "method": "add", "params": [2, 3], "id": 1},{"jsonrpc": "2.0", "method": "multiply", "params": [2, 30], "id": 2}]' http://127.0.0.1:8000/

Invoke-RestMethod -Uri "http://127.0.0.1:8000/" -Method Post -Headers @{ "Content-Type" = "application/json" }  -Body '[{"jsonrpc":"2.0","method":"add","params":[2,3],"id":1},{"jsonrpc":"2.0","method":"multiply","params":[2,30],"id":2}]'

安装fastmcp

uv add fastmcp

运行MCP检查器

uv run fastmcp dev inspector TestMPCserver.py 

运行MCP服务器

uv run fastmcp run TestMPCserver.py

连接到cluade桌面

uv run fastmcp install claude-desktop TestMPCserver.py

运行MCP服务器

uv run fastmcp run DataprovidersMCPServer.py

连接到cluade桌面

uv run fastmcp install claude-desktop DataprovidersMCPServer.py
uv add langchain langchain-openai langchain-mcp-adapters python-dotenv streamlit logging pandas fastmcp python-dotenv jsonrpcserver uvicorn streamlit langchain-ollama fastapi
 uvicorn serversendevent:app
 uvicorn Streamable:app

流式HTTP演示

该项目包括使用FastAPI的流式HTTP端点演示 StreamingResponse.

启动流服务器

uv run uvicorn Streamable:app --reload

服务器将在以下时间运行 http://127.0.0.1:8000/stream 并以1秒的间隔发送10个块。

运行流客户端

python StreamableClient.py

客户端演示了使用流式响应的异步和同步方法。

卷曲测试

# Using curl (Linux/macOS/Git Bash)
curl http://127.0.0.1:8000/stream

# Using Invoke-RestMethod (PowerShell)
Invoke-RestMethod -Uri "http://127.0.0.1:8000/stream" -Method Get

VS代码调试

A. launch.json 文件提供在 .vscode 目录,以便使用VS代码进行调试。您可以在中设置断点 main.py 并运行“Python:FastAPI”配置。

目录标签

目录标签

PythonClaude本地部署JSON-RPCFastAPI服务器

支持客户端

Claude

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Python

部署方式(deploymentType,部署类型)

remote-capable

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiononeremote-capable

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP