【技术文档摘要】
版本: 1.1.0
此模型上下文协议(MCP)服务器提供了一个高级接口,使AI代理(如Cursor或Claude Desktop中的代理)能够与Hasura GraphQL端点进行交互。它允许代理发现API结构,执行只读查询和突变(需谨慎),预览数据,执行聚合操作,并检查服务健康状态。
该服务器通过允许大型语言模型根据自然语言请求动态利用您的Hasura API来增强其功能。
此服务器公开了以下MCP功能:
资源:
hasura:/schema)
application/json工具:
run_graphql_query
query { users { id name } }{ query: string, variables?: object }mutation开头的字符串。主要依赖于查询本身是只读的。run_graphql_mutation
mutation { insert_users_one(object: {name: "Test"}) { id } }{ mutation: string, variables?: object }list_tables
{ schemaName?: string } (可选模式名称,如果可能,尝试从字段描述中推断,默认概念上为'public')describe_table
{ tableName: string, schemaName?: string }list_root_fields
{ fieldType?: 'QUERY' | 'MUTATION' | 'SUBSCRIPTION' } (可选过滤器)describe_graphql_type
{ typeName: string } (区分大小写的类型名称)preview_table_data
{ tableName: string, limit?: number }aggregate_data
{ tableName: string, aggregateFunction: 'count'|'sum'|'avg'|'min'|'max', field?: string, filter?: object }health_check
{ __typename })作出响应。可选地检查已知的具体HTTP健康端点URL。{ healthEndpointUrl?: string } (可选具体健康URL).nvmrc或package.json engines)pnpm(或npm/yarn,相应调整命令)# git clone <repository_url>
# cd mcp-hasura-advanced
pnpm install
pnpm run build
这会将TypeScript代码编译到dist目录中。在终端中执行编译脚本,提供Hasura端点URL和可选的管理员密钥:
# 使用package.json中定义的pnpm start脚本
pnpm start <HASURA_GRAPHQL_ENDPOINT> [ADMIN_SECRET]
# 或直接使用Node
node dist/index.js <HASURA_GRAPHQL_ENDPOINT> [ADMIN_SECRET]
示例:
pnpm start https://my-hasura.cloud/v1/graphql mysecretkey123
或
node dist/index.js https://my-hasura.cloud/v1/graphql mysecretkey1
如果不需要管理员密钥(使用默认角色权限):
pnpm start https://my-hasura.cloud/v1/graphql
服务器将启动,尝试初始模式内省,连接到STDIO传输,并将状态消息记录到stderr。它监听stdin上的MCP JSON-RPC请求并将响应发送到stdout。
要将此服务器连接到MCP客户端(如Cursor):
which node。mcp-hasura-advanced目录并运行pwd。将结果追加/dist/index.js。pwd的输出。settings.json,Claude Desktop的claude_desktop_config.json)。cursor.customMcpServers数组,Claude Desktop的mcpServers对象)。示例Cursor settings.json:
{
// ...其他设置...
"cursor.customMcpServers": [
// ...其他服务器...
{
"name": "我的高级Hasura服务器", // 在Cursor UI中显示的名称
"command": "/path/to/your/node", // <<< 来自'which node'的绝对路径
"args": [
"/absolute/path/to/mcp-hasura-advanced/dist/index.js", // <<< 编译脚本的绝对路径
"https://YOUR_HASURA_ENDPOINT.com/v1/graphql", // <<< 您的端点
"YOUR_ADMIN_SECRET" // <<< 您的密钥(如果没有密钥则移除)
],
// 可选但推荐以保持模块解析一致性:
"cwd": "/absolute/path/to/mcp-hasura-advanced" // <<< 项目的绝对路径
}
]
}
示例Claude Desktop claude_desktop_config.json:
{
"mcpServers": {
// ...其他服务器...
"hasura-advanced": { // Claude内部使用的键
"command": "/path/to/your/node", // <<< 来自'which node'的绝对路径
"args": [
"/absolute/path/to/mcp-hasura-advanced/dist/index.js", // <<< 编译脚本的绝对路径
"https://YOUR_HASURA_ENDPOINT.com/v1/graphql", // <<< 您的端点
"YOUR_ADMIN_SECRET" // <<< 您的密钥(如果没有密钥则移除)
],
// 可选:
// "cwd": "/absolute/path/to/mcp-hasura-advanced"
}
}
}
/path/to/...,https://YOUR...,YOUR_ADMIN_SECRET)为实际值。{ products { name price } }”)。pnpm run dev <ENDPOINT> [SECRET]直接用ts-node运行服务器以加快迭代速度(无需构建步骤)。pnpm start ...)并将其JSON-RPC请求管道化到其stdin来单独测试各个工具。