Julia MCP服务器
Julia中的模型上下文协议(MCP)服务器实现,为AI代理提供了交互工具。
✅ 验证工作: 通过WSL在Windows上与Claude Desktop成功测试,并集成了完整的Node.js MCP包装器。
概述
该项目通过stdio传输实现了遵循JSON-RPC 2.0规范的MCP服务器。它提供了一个框架,用于创建可由Claude Code等AI代理调用的自定义工具。通过HTTP桥和Node.js MCP包装器实现完整的Windows Claude Desktop集成。
特性
核心MCP功能
- 通过标准输入/标准输出进行JSON-RPC 2.0通信
- MCP协议实现
- 可扩展工具系统
- 跨平台支持(Windows、Linux、macOS、WSL)
MCP服务器套件
- PostgreSQL服务器:高级数据库操作、查询、事务
- 文件服务器:通过跨平台路径处理保护文件操作
- 数据库管理服务器:数据库/用户管理、模式操作、导入/导出
- HTTP网桥:用于Windows Claude Desktop访问的REST API端点
可用工具
- 数据库操作:SQL查询、表管理、面向数据库的连接池
- 文件操作:使用安全沙盒读取、写入和创建目录
- 数据库管理:创建/删除数据库、用户管理、权限
- 数据导入/导出:JSON和CSV支持模式验证
- JSON模式到SQL:从JSON模式自动创建表
- 跨数据库迁移:在数据库实例之间传输数据
Windows集成和文档
- HTTP端点:用于Windows Claude Desktop的REST API访问
- WSL大桥:无缝窗口↔ WSL通信
- 自动配置:自动WSL IP检测和Claude配置生成
- PowerShell集成:本机Windows HTTP命令
- 双模服务器:同时支持stdio MCP和HTTP REST API
- 自我记录:每台服务器都提供全面的文档
/mcp/docs
项目结构
julia_mcp_server/
├── Project.toml # Julia project configuration
├── src/
│ ├── JuliaMCPServer.jl # Main module
│ ├── jsonrpc.jl # JSON-RPC implementation
│ ├── mcp.jl # MCP protocol handlers
│ └── server.jl # Server runtime
├── example.jl # Example server with sample tools
├── file_server_example.jl # File server with filesystem tools
├── postgres_example.jl # PostgreSQL database server
├── db_admin_example.jl # Database administration server
├── test_mcp.jl # Test utilities
└── README.md快速开始
适用于Claude桌面用户
WSL/Linux用户
- 单线安装和设置:
curl -fsSL https://raw.githubusercontent.com/SerenaMichaels/MCPJuliaServer/main/scripts/install.sh | bash- 配置Claude桌面:
./claude_config/setup_claude_config.sh- 自动启动服务器(可选):
sudo ./scripts/setup-services.shWindows用户(Windows上的克劳德桌面→ WSL服务器)
如果您在Windows上运行Claude Desktop,但想在WSL中使用MCP服务器:
- 在WSL中-安装和设置服务器:
# Install the MCP servers in WSL
curl -fsSL https://raw.githubusercontent.com/SerenaMichaels/MCPJuliaServer/main/scripts/install.sh | bash
# Setup HTTP endpoints for Windows access
./windows_config/setup_windows_access.sh start这将:
- 在端口8080-8083上启动HTTP服务器 - 自动检测您的WSL IP地址 - 生成Windows Claude桌面配置 - 显示设置说明
- 在Windows中-配置Claude桌面:
- 将生成的配置文件复制到Windows - 地点: %APPDATA%\Claude\claude_desktop_config.json - 重新启动克劳德桌面
- 可用的Windows MCP服务器:
- 📊 mcp postgres http:SQL查询和数据库操作 - 📁 mcp文件http:WSL中的文件系统操作 - 🔧 mcp数据库管理员http:数据库管理 - 🎯 mcp编排器http:多服务器工作流
Claude桌面配置详细信息
每个MCP服务器在其文档中都提供了完整的Claude Desktop配置。访问文档:
- PostgreSQL: http://YOUR_WSL_IP:8080/(自动重定向到文档)
- 文件操作: http://YOUR_WSL_IP:8081/(自动重定向到文档)
- 数据库管理员: http://YOUR_WSL_IP:8082/(自动重定向到文档)
- 编排者: http://YOUR_WSL_IP:8083/(自动重定向到文档)
直接文档URL:
- PostgreSQL: http://YOUR_WSL_IP:8080/mcp/docs
- 文件操作: http://YOUR_WSL_IP:8081/mcp/docs
- 数据库管理员: http://YOUR_WSL_IP:8082/mcp/docs
- 编排者: http://YOUR_WSL_IP:8083/mcp/docs
克劳德桌面配置示例:
{
"mcpServers": {
"mcp-postgres-http": {
"command": "node",
"args": ["-e", "const http = require('http'); const data = JSON.stringify({name: process.argv[2], arguments: JSON.parse(process.argv[3] || '{}')}); const req = http.request('http://172.27.85.131:8080/mcp/tools/call', {method: 'POST', headers: {'Content-Type': 'application/json', 'Content-Length': data.length}}, res => {let body = ''; res.on('data', d => body += d); res.on('end', () => {try {const result = JSON.parse(body); console.log(JSON.stringify(result.result || result));} catch(e) {console.log(body);}});}); req.write(data); req.end();"],
"env": {},
"description": "PostgreSQL MCP Server via HTTP - Execute SQL queries and database operations"
},
"mcp-file-http": {
"command": "node",
"args": ["-e", "const http = require('http'); const data = JSON.stringify({name: process.argv[2], arguments: JSON.parse(process.argv[3] || '{}')}); const req = http.request('http://172.27.85.131:8081/mcp/tools/call', {method: 'POST', headers: {'Content-Type': 'application/json', 'Content-Length': data.length}}, res => {let body = ''; res.on('data', d => body += d); res.on('end', () => {try {const result = JSON.parse(body); console.log(JSON.stringify(result.result || result));} catch(e) {console.log(body);}});}); req.write(data); req.end();"],
"env": {},
"description": "File Operations MCP Server via HTTP - Read, write, and manage files"
},
"mcp-db-admin-http": {
"command": "node",
"args": ["-e", "const http = require('http'); const data = JSON.stringify({name: process.argv[2], arguments: JSON.parse(process.argv[3] || '{}')}); const req = http.request('http://172.27.85.131:8082/mcp/tools/call', {method: 'POST', headers: {'Content-Type': 'application/json', 'Content-Length': data.length}}, res => {let body = ''; res.on('data', d => body += d); res.on('end', () => {try {const result = JSON.parse(body); console.log(JSON.stringify(result.result || result));} catch(e) {console.log(body);}});}); req.write(data); req.end();"],
"env": {},
"description": "Database Administration MCP Server via HTTP - Create databases, manage users"
},
"mcp-orchestrator-http": {
"command": "node",
"args": ["-e", "const http = require('http'); const data = JSON.stringify({name: process.argv[2], arguments: JSON.parse(process.argv[3] || '{}')}); const req = http.request('http://172.27.85.131:8083/mcp/tools/call', {method: 'POST', headers: {'Content-Type': 'application/json', 'Content-Length': data.length}}, res => {let body = ''; res.on('data', d => body += d); res.on('end', () => {try {const result = JSON.parse(body); console.log(JSON.stringify(result.result || result));} catch(e) {console.log(body);}});}); req.write(data); req.end();"],
"env": {},
"description": "MCP Orchestrator via HTTP - Execute multi-server workflows and complex operations"
}
}
}重要提示:
- 替换
172.27.85.131使用您的实际WSL IP地址(使用hostname -IWSL) - 运行时,配置会自动生成,并使用正确的IP
setup_windows_access.sh - Node.js是必需的 在Windows上,MCP包装器才能正常工作
- 安装Node.js并复制配置后,完全重新启动Claude Desktop
已验证的工作设置: ✅ Claude Desktop提供4台MCP服务器:
- PostgreSQL MCP服务器 -执行SQL查询、列出表、描述具有数据库定位支持的模式
- 文件操作MCP服务器 -读取、写入、管理文件和目录(默认挂载:
D:\MCP-Agents) - 数据库管理MCP服务器 -创建数据库,导入/导出数据
- MCP编排器服务器 -多服务器工作流和自动化
✅ 数据库定位已修复: 现在,当指定时,表会在正确的数据库中创建(例如,在“TestDB”中创建表,而不是默认为“postgres”数据库)
故障排除:
- 如果服务器在Claude Desktop中显示“失败”,请检查Windows上是否安装了Node.js
- 更改任何配置后重新启动Claude Desktop
- 检查服务器日志
%APPDATA%\Claude\logs\mcp-server-*.log用于调试
Windows服务器管理:
# In WSL - manage HTTP servers
./windows_config/setup_windows_access.sh status # Check status
./windows_config/setup_windows_access.sh stop # Stop servers
./windows_config/setup_windows_access.sh restart # Restart servers本机Windows用户
有关本机Windows安装(无WSL),请参阅 Windows安装指南.
用法
运行示例服务器
基本示例服务器(计算器、随机、系统信息):
cd julia_mcp_server
julia example.jl文件服务器示例(文件操作):
cd julia_mcp_server
julia file_server_example.jlPostgreSQL数据库服务器(数据库操作):
cd julia_mcp_server
julia postgres_example.jl数据库管理服务器(数据库管理):
cd julia_mcp_server
julia db_admin_example.jl文件服务器会自动检测操作系统并使用适当的默认值:
- 视窗:
D:\MCP-Agents - WSL:
/mnt/d/MCP-Agents(如果安装了D:驱动器) - Linux:
~/MCP-Agents
您可以使用环境变量覆盖默认值:
MCP_FILE_SERVER_BASE=/custom/path julia file_server_example.jlPostgreSQL服务器可以配置环境变量:
POSTGRES_HOST=localhost \
POSTGRES_PORT=5432 \
POSTGRES_USER=postgres \
POSTGRES_PASSWORD=mypassword \
POSTGRES_DB=mydatabase \
julia postgres_example.jl两个PostgreSQL服务器使用相同的配置格式。数据库管理服务器包括基本PostgreSQL服务器的所有功能以及高级管理工具。
服务器将启动并在stdin上监听JSON-RPC消息,在stdout上响应。
测试服务器
您可以通过手动发送JSON-RPC消息来测试服务器:
- 初始化服务器:
{"jsonrpc": "2.0", "method": "initialize", "params": {}, "id": 1}- 列出可用工具:
{"jsonrpc": "2.0", "method": "tools/list", "params": {}, "id": 2}- 调用工具:
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "calculator", "arguments": {"operation": "add", "a": 5, "b": 3}}, "id": 3}文件服务器示例:
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "list_files", "arguments": {"path": "."}}, "id": 4}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "write_file", "arguments": {"path": "hello.txt", "content": "Hello World!"}}, "id": 5}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "read_file", "arguments": {"path": "hello.txt"}}, "id": 6}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "create_directory", "arguments": {"path": "my_folder"}}, "id": 7}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "delete_file", "arguments": {"path": "hello.txt"}}, "id": 8}PostgreSQL数据库示例:
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "list_databases", "arguments": {}}, "id": 9}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "list_tables", "arguments": {"schema": "public"}}, "id": 10}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "execute_query", "arguments": {"query": "SELECT version()"}}, "id": 11}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "describe_table", "arguments": {"table": "users", "schema": "public"}}, "id": 12}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "execute_transaction", "arguments": {"queries": ["CREATE TABLE test (id INT)", "INSERT INTO test VALUES (1)", "DROP TABLE test"]}}, "id": 13}PostgreSQL数据库定位示例:
# Execute SQL in specific database
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "execute_sql", "arguments": {"query": "CREATE TABLE users (id SERIAL PRIMARY KEY, name VARCHAR(50))", "database": "TestDB"}}, "id": 14}
# List tables in specific database
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "list_tables", "arguments": {"database": "TestDB"}}, "id": 15}
# Describe table in specific database
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "describe_table", "arguments": {"table_name": "users", "database": "TestDB"}}, "id": 16}数据库管理示例:
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "create_database", "arguments": {"name": "my_new_db", "owner": "postgres"}}, "id": 14}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "create_user", "arguments": {"username": "app_user", "password": "secret123", "createdb": true}}, "id": 15}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "grant_privileges", "arguments": {"username": "app_user", "database": "my_new_db", "privileges": ["CONNECT", "CREATE"]}}, "id": 16}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "create_table_from_json", "arguments": {"table": "users", "schema": "{\"properties\":{\"id\":{\"type\":\"integer\"},\"name\":{\"type\":\"string\"}},\"primary_key\":[\"id\"]}"}}, "id": 17}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "import_data", "arguments": {"table": "users", "data": "[{\"id\":1,\"name\":\"Alice\"},{\"id\":2,\"name\":\"Bob\"}]", "format": "json"}}, "id": 18}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "export_data", "arguments": {"table": "users", "format": "csv", "limit": 100}}, "id": 19}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "export_schema", "arguments": {"database": "my_new_db", "format": "sql"}}, "id": 20}
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "drop_database", "arguments": {"name": "my_new_db", "force": true}}, "id": 21}创建自定义工具
要创建自定义工具,请定义一个函数并将其添加到服务器:
function my_custom_tool(args::Dict{String,Any})
# Your tool logic here
return "Tool result"
end
# Define the JSON schema for the tool's input
schema = Dict{String,Any}(
"type" => "object",
"properties" => Dict{String,Any}(
"param1" => Dict{String,Any}(
"type" => "string",
"description" => "Description of parameter"
)
),
"required" => ["param1"]
)
# Add to server
add_tool!(server, MCPTool(
"my_tool",
"Description of what the tool does",
schema,
my_custom_tool
))MCP协议支持
此实现支持以下MCP方法:
initialize-初始化服务器连接tools/list-列出可用工具tools/call-执行特定工具
依赖项
- 朱莉娅1.6+
- JSON3.jl-用于JSON解析和生成
- UUID.jl-用于生成唯一标识符
- LibPQ.jl-用于PostgreSQL数据库连接(仅限postgres.example.jl)
- HTTP.jl-用于HTTP服务器功能(Windows网桥)
Windows特定故障排除
常见的Windows+WSL问题
Windows Claude的“连接被拒绝”
# In WSL - check server status
./windows_config/setup_windows_access.sh status
# Test connectivity from WSL
curl http://localhost:8080/mcp/health
# Check WSL IP address
hostname -I“服务器没有响应”
# Check server logs
tail -f logs/*_http.log
# Restart servers
./windows_config/setup_windows_access.sh restart
# Verify Julia packages
julia --project=. -e "using Pkg; Pkg.status()"“PowerShell执行错误”
- 确保PowerShell执行策略允许脚本
- 检查WSL通信的Windows防火墙设置
- 验证Claude配置中的WSL IP地址是否与当前IP匹配
网络连接测试:
# From Windows PowerShell - test WSL server
Invoke-RestMethod -Uri http://YOUR_WSL_IP:8080/mcp/healthWindows防火墙配置
如果Windows Claude无法访问WSL服务器:
- Windows设置 → 隐私和安全 → Windows安全 → 防火墙和网络保护
- 允许应用程序通过防火墙
- 添加PowerShell并允许专用网络访问
- 或暂时禁用防火墙进行测试
WSL网络问题
重新启动后WSL IP更改:
# Get current WSL IP
hostname -I | awk '{print $1}'
# Update Windows Claude config with new IP
./windows_config/setup_windows_access.sh start端口冲突:
# Check if ports are in use
netstat -tulpn | grep :8080
# Use different ports if needed
MCP_HTTP_PORT=9080 ./windows_config/setup_windows_access.sh start详细日志
启用调试日志以进行故障排除:
export MCP_DEBUG_COMMUNICATION=true
export MCP_HTTP_DEBUG=true
./windows_config/setup_windows_access.sh start服务器文档和API参考
每个MCP服务器都提供全面的自文档功能:
📖 实时文档端点
易于访问的网址(自动重定向):
- PostgreSQL服务器: http://YOUR_WSL_IP:8080/
- 文件操作服务器: http://YOUR_WSL_IP:8081/
- 数据库管理服务器: http://YOUR_WSL_IP:8082/
- 编排器服务器: http://YOUR_WSL_IP:8083/
直接文档URL:
- PostgreSQL服务器: http://YOUR_WSL_IP:8080/mcp/docs
- 文件操作服务器: http://YOUR_WSL_IP:8081/mcp/docs
- 数据库管理服务器: http://YOUR_WSL_IP:8082/mcp/docs
- 编排器服务器: http://YOUR_WSL_IP:8083/mcp/docs
🌐 API端点(所有服务器)
- 得到/ -自动重定向到文档(HTTP 302)
- GET/mcp/健康 -服务器健康检查
- GET/mcp/info -服务器信息和功能
- GET/mcp/docs -完整的交互式文档
- POST/mcp/工具/列表 -列出所有具有模式的可用工具
- POST/mcp/工具/调用 -执行特定工具
- POST/mcp/编排器 -直接工作流执行(仅限编排器)
📋 文档功能
- 自动生成:文档是根据实际服务器能力生成的
- 工具架构:所有工具的完整JSON模式及其示例
- Claude桌面集成:复制粘贴就绪的PowerShell配置
- WSL IP检测:自动检测并显示当前WSL IP
- 服务器特定指南:为每种服务器类型量身定制文档
- 故障排除:常见问题和解决方案
- 专业用户界面:响应式HTML界面,语法高亮显示
- 用户友好的URL:根URL会自动重定向到文档
- 更好的错误消息:访问无效端点时提供明确的指导
🤖 适用于Claude桌面用户
Claude可以查询文档端点:
- 动态发现服务器功能
- 获取完整的工具模式,以更好地验证参数
- 访问故障排除指南
- 根据可用工具制定更好的计划
示例:Claude查询服务器文档:
Claude can visit http://172.27.85.131:8080/mcp/docs to see all PostgreSQL server capabilities,
tool schemas, and usage examples, enabling more efficient query planning.其他文件
- 安装指南: 安装.md
- 站点配置: SITE_CONFIG.md
- Windows安装程序: windows_configure/README.md
- 克劳德配置: claude_config/README.md
许可证
这是Julia中MCP服务器的演示实现。
