本文档详细说明如何实现MCP服务器来连接内网服务器(172.16.2.15)上的InterSystems IRIS数据库。
实现一个MCP(Model Context Protocol)服务器,为DRG医保控费预警系统提供统一的IRIS数据库访问接口。
服务器地址: http://172.16.2.15:52773
命名空间: USER
账户信息:
- 用户名: _system
- 密码: pryk@2020
接口端点: /csp/drg/sysInternalMutiple
mcp-server-config.yaml)位于项目根目录,包含完整的MCP服务器配置:
# 服务器连接配置
server:
type: "http"
base_url: "http://172.16.2.15:52773"
timeout: 30
# 数据库连接配置
database:
type: "intersystems-iris"
namespace: "USER"
credentials:
username: "_system"
password: "pryk@2020"
.codebuddy/mcp-drg-iris.json)专为CodeBuddy IDE设计的MCP集成配置,位于.codebuddy目录:
{
"name": "drg-iris-mcp",
"type": "mcp-server",
"configurations": {
"production": {
"server_url": "http://172.16.2.15:52773",
"namespace": "USER"
}
}
}
mcp-client-config.json)MCP客户端配置,用于连接MCP服务器:
{
"mcp": {
"servers": [{
"name": "drg-iris-server",
"url": "http://localhost:8090",
"auth": {
"type": "api_key",
"value": "drg-mcp-access-key-2026"
}
}]
}
}
初始化项目
mkdir drg-mcp-server
cd drg-mcp-server
npm init -y
npm install express axios body-parser cors
// 中间件 app.use(express.json()); app.use(cors());
// 代理接口 app.post('/invoke', async (req, res) => { const { code, params, session } = req.body;
// 构建请求数据 const requestData = { code: code, params: params, session: session };
// 转发到IRIS服务器 const response = await axios.post( 'http://172.16.2.15:52773/csp/drg/sysInternalMutiple', requestData, { auth: {
username: '_system',
password: 'pryk@2020'
} } );
res.json(response.data); });
// 启动服务器
const PORT = 8090;
app.listen(PORT, () => {
console.log(MCP服务器运行在 http://localhost:${PORT});
});
```
Python客户端 ```python
import requests
class DRGIRISMCPClient:
def __init__(self, base_url, api_key):
self.base_url = base_url
self.api_key = api_key
def invoke_interface(self, interface_code, params):
headers = {
"X-API-Key": self.api_key,
"Content-Type": "application/json"
}
data = {
"code": interface_code,
"params": params,
"session": [{
"userID": "158",
"userCode": "admin"
# ... 其他session字段
}]
}
response = requests.post(
f"{self.base_url}/invoke",
json=data,
headers=headers
)
return response.json()
2. **Node.js客户端**
```javascript
// mcp-drg-iris-nodejs.js
const axios = require('axios');
class DRGIRISMCPClient {
constructor(config) {
this.config = config;
this.instance = axios.create({
baseURL: config.baseURL,
headers: {
'X-API-Key': config.apiKey
}
});
}
async invokeInterface(interfaceCode, params) {
const response = await this.instance.post('/invoke', {
code: interfaceCode,
params: params
});
return response.data;
}
}
创建CodeBuddy配置文件
将 .codebuddy/mcp-drg-iris.json 放置在项目根目录的 .codebuddy 文件夹中。
在CodeBuddy中启用MCP服务器
打开CodeBuddy IDE
进入设置 → MCP集成
添加新的MCP服务器
加载 mcp-drg-iris.json 配置文件
测试连接 ```bash
node proxy-server.js
curl -X POST http://localhost:8090/iris-api/invoke \ -H "X-API-Key: drg-mcp-access-key-2026" \ -H "Content-Type: application/json" \ -d '{
"code": "02010404",
"params": []
}'
---
## 4. 接口调用示例
### 4.1 通用请求格式
```json
{
"code": "接口代码",
"params": [
{
"参数名": "参数值"
}
],
"session": [
{
"userID": "158",
"userCode": "admin",
// ... 其他session信息
}
]
}
查询接口服务列表
const result = await client.invokeInterface('02010404', []);
javascript
const result = await client.queryWarningRecords({
startDate: '2026-01-01',
endDate: '2026-04-09',
warningLevel: '高',
page: 1,
limit: 10
});
查询科室盈亏
const result = await client.queryDeptProfit({
startDate: '2026-01-01',
endDate: '2026-03-31',
page: 1,
limit: 15
});
authentication:
api_key:
enabled: true
header_name: "X-API-Key"
required: true
database:
credentials:
username: "_system"
password: "pryk@2020"
connection_params:
charset: "UTF-8"
pool_size: 10
security:
cors:
enabled: true
allowed_origins: ["http://localhost:5173", "http://localhost:8090"]
allowed_methods: ["GET", "POST"]
# 安装依赖
npm install
# 启动开发服务器
npm run dev
# 启动MCP服务器
node server.js
使用PM2进程管理
npm install -g pm2
pm2 start server.js --name "drg-mcp-server"
pm2 save
pm2 startup
location / {
proxy_pass http://localhost:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
} } ```
设置环境变量
export IRIS_HOST="localhost"
export IRIS_PORT="52773"
export IRIS_USERNAME="_system"
export IRIS_PASSWORD="pryk@2020"
export MCP_API_KEY="drg-mcp-access-key-2026"
| 问题 | 可能原因 | 解决方案 |
|---|---|---|
| 连接超时 | 网络问题或IRIS服务器未启动 | 检查服务器状态和网络连接 |
| 认证失败 | 用户名或密码错误 | 验证IRIS账户信息 |
| API调用失败 | 接口代码错误 | 检查接口代码和参数格式 |
| CORS错误 | 浏览器安全策略 | 配置正确的CORS头 |
// 配置详细日志
const winston = require('winston');
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' })
]
});
// 添加健康检查端点
app.get('/health', (req, res) => {
res.json({
status: 'healthy',
timestamp: new Date().toISOString(),
server: 'mcp-drg-server',
version: '1.0.0'
});
});
连接池配置
database:
connection_params:
pool_size: 20
max_lifetime: 600
yaml
cache:
enabled: true
ttl: 300
max_size: 1000
请求限流
security:
rate_limiting:
enabled: true
requests_per_minute: 60
mcp-server-config.yaml - 服务器配置mcp-client-config.json - 客户端配置mcp-drg-iris-python.py - Python客户端示例mcp-drg-iris-nodejs.js - Node.js客户端示例如需技术支持,请联系DRG开发团队: