MCP多工具服务器
带有PostgreSQL工具的可扩展MCP服务器。TypeScript、Zod验证、模块化架构。
它做什么
- 查询PostgreSQL数据库(列出表、描述模式、运行SELECT查询)
- 具有验证功能的只读、安全查询
- 易于扩展,有更多连接器(S3、Redis等)
快速设置
npm install
cp config.example.json config.json
# Edit config.json with your DB credentials
npm run build配置
对于本地开发人员: config.json
{
"enablePostgres": true,
"postgres": {
"host": "localhost",
"port": 5432,
"database": "mydb",
"user": "readonly_user",
"password": "your_password",
"schema": "public"
}
}对于跑步者设置:配置中的环境变量
{
"mcpServers": {
"postgres-tools": {
"command": "node",
"args": ["/absolute/path/to/dist/index.js"],
"env": {
"ENABLE_POSTGRES": "true",
"PGHOST": "localhost",
"PGPORT": "5432",
"PGDATABASE": "mydb",
"PGUSER": "readonly_user",
"PGPASSWORD": "your_password"
}
}
}
}可用工具
postgres_list_tables-列出架构中的表postgres_describe_table-显示表结构(列、类型)postgres_query-运行SELECT查询(默认最多100行)
快速只读用户设置
CREATE ROLE mcp_readonly WITH LOGIN PASSWORD 'secure_password';
GRANT CONNECT ON DATABASE mydb TO mcp_readonly;
GRANT USAGE ON SCHEMA public TO mcp_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO mcp_readonly;发展
npm run dev # Dev mode with reload
npm test # Run tests
npm run lint # Lint code
npm run format # Format codeMCP检验员测试
测试您的服务器:
npm run build
npx @modelcontextprotocol/inspector node dist/index.js在以下位置打开web UI http://localhost:5173 测试工具、查看日志和调试。
对于环境变量:
ENABLE_POSTGRES=true PGHOST=localhost PGDATABASE=mydb PGUSER=user PGPASSWORD=pass \
npx @modelcontextprotocol/inspector node dist/index.js延伸
看 贡献.md 获取分步指南。快速版本:
- 添加配置模式(Zod+类型)
- 在中创建连接器
src/connectors/ - 在中创建工具
src/tools/your-tool/ - 注册
src/index.ts - 编写测试
建筑
src/
├── config/ # Zod validation, loads config.json or env vars
├── connectors/ # DB connection managers
├── tools/ # MCP tool implementations
├── utils/ # Logging, errors
└── server.ts # MCP server setup