data-tool-xjc
README.md
# data-tool-xjc
一个基于 [MCP(Model Context Protocol)](https://modelcontextprotocol.io) Python SDK 的最小 MCP Server 示例,通过 **stdio** 传输向大模型客户端暴露工具能力。
仓库地址:<https://github.com/xjc12138-shift/MCP12138>
## 功能
| 工具名 | 描述 | 返回值 |
| --- | --- | --- |
| `get_time` | 返回当前的年月日 | 形如 `2026-11-26` 的字符串 |
## 目录结构
```
.
├── mcp-server-stdio.py # MCP Server 入口,定义工具并启动 stdio 服务
├── requirements.txt # 依赖清单
├── chatmcp.yaml # MCP 托管/发布描述文件
├── LICENSE
└── README.md
```
## 环境要求
- Python 3.10+
- 依赖:`mcp>=1.28.1`
## 安装
从源码安装:
```bash
git clone https://github.com/xjc12138-shift/MCP12138.git
cd MCP12138
pip install -r requirements.txt
```
## 运行
```bash
python mcp-server-stdio.py
```
启动后进程会以 stdio 方式等待 JSON-RPC 消息,**不要手动在终端输入内容**,应由 MCP 客户端连接。直接在终端运行看起来像“卡住”,属于正常现象。
## 工具说明
`get_time()` 无需参数,返回服务器本地时区的当前日期:
```python
@mcp.tool()
def get_time():
"""返回当前的年月日,格式YYYY-MM-DD"""
return datetime.now().strftime('%Y-%m-%d')
```
## 接入 MCP 客户端
### 方式一:Claude Desktop / 兼容客户端配置
```json
{
"mcpServers": {
"data-tool-xjc": {
"command": "python",
"args": ["/absolute/path/to/MCP12138/mcp-server-stdio.py"]
}
}
}
```
### 方式二:LangChain / LangGraph 客户端
```python
from langchain_mcp_adapters.client import MultiServerMCPClient
client = MultiServerMCPClient({
"data-tool-xjc": {
"transport": "stdio",
"command": "python",
"args": ["mcp-server-stdio.py"],
}
})
tools = await client.get_tools()
```
## 注意事项
- `command` 建议使用当前环境的绝对路径(例如 `E:\soft\Anaconda\envs\env\python.exe`),避免因 PATH 找不到解释器导致 `FileNotFoundError`。
- stdio 传输只适合本地进程调用,如需公网共享请改用 `streamable_http` 或 SSE 传输。
- 若客户端报 `Connection closed`,先在终端用同样的 `command` + `args` 手动启动一次,确认服务端没有启动即退出的错误。
## License
[MIT](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues