@pkwadsy/grok-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +88 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# grok-mcp
|
|
2
|
+
|
|
3
|
+
MCP server that wraps the xAI Grok API. Lets Claude and other AI agents delegate thinking, planning, and real-time search to Grok.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @pkwadsy/grok-mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or use directly with npx:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx @pkwadsy/grok-mcp
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
You need an xAI API key from [console.x.ai](https://console.x.ai).
|
|
18
|
+
|
|
19
|
+
## Configure in Claude Code
|
|
20
|
+
|
|
21
|
+
Add to your project's `.mcp.json`:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"mcpServers": {
|
|
26
|
+
"grok": {
|
|
27
|
+
"type": "stdio",
|
|
28
|
+
"command": "npx",
|
|
29
|
+
"args": ["@pkwadsy/grok-mcp"],
|
|
30
|
+
"env": {
|
|
31
|
+
"XAI_API_KEY": "your-xai-api-key"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Tool: `ask_grok`
|
|
39
|
+
|
|
40
|
+
Single tool with options for different use cases.
|
|
41
|
+
|
|
42
|
+
### Parameters
|
|
43
|
+
|
|
44
|
+
| Parameter | Type | Required | Description |
|
|
45
|
+
|-----------|------|----------|-------------|
|
|
46
|
+
| `prompt` | string | yes | The question or task for Grok |
|
|
47
|
+
| `system_prompt` | string | no | Custom system prompt |
|
|
48
|
+
| `model` | string | no | Model to use (default: `grok-4.20-reasoning`) |
|
|
49
|
+
| `web_search` | boolean | no | Enable real-time web search |
|
|
50
|
+
| `x_search` | boolean | no | Enable X/Twitter search |
|
|
51
|
+
|
|
52
|
+
### Available Models
|
|
53
|
+
|
|
54
|
+
- `grok-4.20-reasoning` — flagship reasoning (default)
|
|
55
|
+
- `grok-4.20-non-reasoning` — fast, no reasoning
|
|
56
|
+
- `grok-4.20-multi-agent` — multi-agent mode, great for architecture and planning
|
|
57
|
+
- `grok-4.1-fast-reasoning` — cheaper reasoning
|
|
58
|
+
- `grok-4.1-fast-non-reasoning` — cheapest, fast
|
|
59
|
+
|
|
60
|
+
### Examples
|
|
61
|
+
|
|
62
|
+
**Ask a question:**
|
|
63
|
+
```
|
|
64
|
+
prompt: "What are the trade-offs between microservices and monoliths?"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Deep architecture planning (multi-agent):**
|
|
68
|
+
```
|
|
69
|
+
prompt: "Design a system architecture for a real-time collaborative editor"
|
|
70
|
+
model: "grok-4.20-multi-agent"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Search the web:**
|
|
74
|
+
```
|
|
75
|
+
prompt: "What happened in tech news today?"
|
|
76
|
+
web_search: true
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Search X/Twitter:**
|
|
80
|
+
```
|
|
81
|
+
prompt: "What are people saying about the new React release?"
|
|
82
|
+
x_search: true
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const apiKey = process.env.XAI_API_KEY;
|
|
6
|
+
if (!apiKey) {
|
|
7
|
+
console.error("XAI_API_KEY environment variable is required");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
const server = new McpServer({
|
|
11
|
+
name: "grok-mcp",
|
|
12
|
+
version: "1.0.0",
|
|
13
|
+
});
|
|
14
|
+
async function callGrok(options) {
|
|
15
|
+
const model = options.model ?? "grok-4.20-reasoning";
|
|
16
|
+
const body = {
|
|
17
|
+
model,
|
|
18
|
+
input: options.messages,
|
|
19
|
+
};
|
|
20
|
+
if (options.tools && options.tools.length > 0) {
|
|
21
|
+
body.tools = options.tools;
|
|
22
|
+
}
|
|
23
|
+
const response = await fetch("https://api.x.ai/v1/responses", {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
Authorization: `Bearer ${apiKey}`,
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(body),
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
const errorText = await response.text();
|
|
33
|
+
throw new Error(`Grok API error (${response.status}): ${errorText}`);
|
|
34
|
+
}
|
|
35
|
+
const data = (await response.json());
|
|
36
|
+
for (const item of data.output) {
|
|
37
|
+
if (item.type === "message" && item.content) {
|
|
38
|
+
for (const block of item.content) {
|
|
39
|
+
if (block.type === "output_text" && block.text) {
|
|
40
|
+
return block.text;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error("No text content in Grok response");
|
|
46
|
+
}
|
|
47
|
+
server.tool("ask_grok", "Ask Grok a question. Grok is great for thinking, planning, architecture, and real-time search via web and X/Twitter. Use web_search for current information from the internet. Use x_search to find and analyze posts on X/Twitter.", {
|
|
48
|
+
prompt: z.string().describe("The question or task for Grok"),
|
|
49
|
+
system_prompt: z
|
|
50
|
+
.string()
|
|
51
|
+
.optional()
|
|
52
|
+
.describe("Custom system prompt to guide Grok's behavior"),
|
|
53
|
+
model: z
|
|
54
|
+
.string()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe("Model to use. Defaults to grok-4.20-reasoning. Options: grok-4.20-reasoning, grok-4.20-non-reasoning, grok-4.20-multi-agent, grok-4.1-fast-reasoning, grok-4.1-fast-non-reasoning"),
|
|
57
|
+
web_search: z
|
|
58
|
+
.boolean()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe("Enable web search for real-time internet information"),
|
|
61
|
+
x_search: z
|
|
62
|
+
.boolean()
|
|
63
|
+
.optional()
|
|
64
|
+
.describe("Enable X/Twitter search to find and analyze posts"),
|
|
65
|
+
}, async ({ prompt, system_prompt, model, web_search, x_search }) => {
|
|
66
|
+
const messages = [];
|
|
67
|
+
if (system_prompt) {
|
|
68
|
+
messages.push({ role: "system", content: system_prompt });
|
|
69
|
+
}
|
|
70
|
+
messages.push({ role: "user", content: prompt });
|
|
71
|
+
const tools = [];
|
|
72
|
+
if (web_search) {
|
|
73
|
+
tools.push({ type: "web_search" });
|
|
74
|
+
}
|
|
75
|
+
if (x_search) {
|
|
76
|
+
tools.push({ type: "x_search" });
|
|
77
|
+
}
|
|
78
|
+
const response = await callGrok({
|
|
79
|
+
messages,
|
|
80
|
+
model,
|
|
81
|
+
tools: tools.length > 0 ? tools : undefined,
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
content: [{ type: "text", text: response }],
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
const transport = new StdioServerTransport();
|
|
88
|
+
await server.connect(transport);
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pkwadsy/grok-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server that wraps the xAI Grok API — delegate thinking, planning, and search to Grok",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"grok-mcp": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mcp",
|
|
20
|
+
"grok",
|
|
21
|
+
"xai",
|
|
22
|
+
"ai",
|
|
23
|
+
"model-context-protocol"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
31
|
+
"zod": "^3.24.4"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^22.15.3",
|
|
35
|
+
"typescript": "^5.8.3"
|
|
36
|
+
}
|
|
37
|
+
}
|