@gravity-ai/index-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 +112 -0
- package/bin/cli.mjs +368 -0
- package/bin/test.mjs +56 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# `@gravity-ai/index-mcp`
|
|
2
|
+
|
|
3
|
+
An [MCP](https://modelcontextprotocol.io/) server that lets AI coding agents
|
|
4
|
+
**discover developer services and get install instructions** from the
|
|
5
|
+
[Gravity Index](https://index.trygravity.ai).
|
|
6
|
+
|
|
7
|
+
Zero dependencies, zero build step — a single Node.js file that speaks
|
|
8
|
+
JSON-RPC 2.0 over stdio.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npx -y @gravity-ai/index-mcp
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## What it does
|
|
17
|
+
|
|
18
|
+
The Gravity Index catalogs ~490 installable developer services (databases,
|
|
19
|
+
auth, payments, hosting, email, monitoring, AI/ML, etc.) with install summaries
|
|
20
|
+
and env vars. This MCP server exposes five tools to any MCP-compatible agent:
|
|
21
|
+
|
|
22
|
+
| Tool | What it does |
|
|
23
|
+
|---|---|
|
|
24
|
+
| `gravity_index_search` | LLM-reasoned recommendation for a stated need, with install steps + setup link |
|
|
25
|
+
| `gravity_index_browse` | List services by category or keyword |
|
|
26
|
+
| `gravity_index_get_service` | Full detail for a single service by slug |
|
|
27
|
+
| `gravity_index_list_categories` | Enumerate all categories with counts |
|
|
28
|
+
| `gravity_index_report_integration` | Record a conversion when the agent finishes the install |
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Installing in Claude Desktop
|
|
33
|
+
|
|
34
|
+
Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
|
|
35
|
+
or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"mcpServers": {
|
|
40
|
+
"gravity-index": {
|
|
41
|
+
"command": "npx",
|
|
42
|
+
"args": ["-y", "@gravity-ai/index-mcp"]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Restart Claude Desktop. You should see the `gravity_index_*` tools listed.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Installing in Cursor
|
|
53
|
+
|
|
54
|
+
Settings → **MCP** → Add server:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"gravity-index": {
|
|
60
|
+
"command": "npx",
|
|
61
|
+
"args": ["-y", "@gravity-ai/index-mcp"]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Installing in Cline / Continue / Zed / Other MCP clients
|
|
70
|
+
|
|
71
|
+
Any MCP client that supports the stdio transport works — point it at the
|
|
72
|
+
command `npx -y @gravity-ai/index-mcp`. No other runtime deps (Python,
|
|
73
|
+
Docker, etc.) are required.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Environment variables
|
|
78
|
+
|
|
79
|
+
| Var | Default | Notes |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `GRAVITY_INDEX_URL` | `https://index.trygravity.ai` | Override for self-hosted or staging |
|
|
82
|
+
| `GRAVITY_PUBLISHER_KEY` | *(unset)* | Your Gravity publisher API key — if set, referral conversions attribute to your account (CPA revenue share) |
|
|
83
|
+
|
|
84
|
+
If you're a platform publisher (building a tool that embeds this MCP for your
|
|
85
|
+
users), set `GRAVITY_PUBLISHER_KEY` so every install attributes to you.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Example conversation
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
you: I need a serverless SQL database with branching
|
|
93
|
+
agent uses gravity_index_search → returns Neon with:
|
|
94
|
+
- npm install @neondatabase/serverless
|
|
95
|
+
- lib/db.ts stub
|
|
96
|
+
- DATABASE_URL env var
|
|
97
|
+
- https://index.trygravity.ai/go/abc123 ← setup link
|
|
98
|
+
- search_id: s_0f9...
|
|
99
|
+
agent: Here's the setup. Open the link above, paste your DATABASE_URL
|
|
100
|
+
back, and I'll wire it up.
|
|
101
|
+
you: [pastes URL] done
|
|
102
|
+
agent uses gravity_index_report_integration(search_id=s_0f9..., integrated_slug=neon)
|
|
103
|
+
→ records the conversion
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## See also
|
|
109
|
+
|
|
110
|
+
- Gravity Index REST API: <https://index.trygravity.ai>
|
|
111
|
+
- Docs: <https://docs.trygravity.ai/gravity-index/introduction>
|
|
112
|
+
- Python MCP (identical tools, requires `python3`): `index/mcp/gravity_index_mcp.py` in the Gravity monorepo
|
package/bin/cli.mjs
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Gravity Index MCP Server — bare stdio JSON-RPC, zero dependencies.
|
|
3
|
+
// Wraps https://index.trygravity.ai as a Model Context Protocol tool server.
|
|
4
|
+
//
|
|
5
|
+
// Install per-project: npm install -g @gravity-ai/index-mcp
|
|
6
|
+
// One-shot: npx -y @gravity-ai/index-mcp
|
|
7
|
+
// Cursor/Claude Desktop: see README.md for the MCP config block.
|
|
8
|
+
|
|
9
|
+
import readline from "node:readline";
|
|
10
|
+
import process from "node:process";
|
|
11
|
+
|
|
12
|
+
const API_URL =
|
|
13
|
+
process.env.GRAVITY_INDEX_URL || "https://index.trygravity.ai";
|
|
14
|
+
const PUBLISHER_KEY = process.env.GRAVITY_PUBLISHER_KEY || "";
|
|
15
|
+
const UA = "GravityIndex-MCP-JS/1.0";
|
|
16
|
+
|
|
17
|
+
async function apiPost(path, body) {
|
|
18
|
+
try {
|
|
19
|
+
const resp = await fetch(`${API_URL}${path}`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: { "Content-Type": "application/json", "User-Agent": UA },
|
|
22
|
+
body: JSON.stringify(body),
|
|
23
|
+
});
|
|
24
|
+
if (!resp.ok) {
|
|
25
|
+
const text = await resp.text();
|
|
26
|
+
return { error: `${resp.status} ${text}` };
|
|
27
|
+
}
|
|
28
|
+
return await resp.json();
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return { error: `Request failed: ${e.name}: ${e.message}` };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function apiGet(path, params) {
|
|
35
|
+
try {
|
|
36
|
+
let url = `${API_URL}${path}`;
|
|
37
|
+
if (params) {
|
|
38
|
+
const qs = new URLSearchParams();
|
|
39
|
+
for (const [k, v] of Object.entries(params)) {
|
|
40
|
+
if (v !== undefined && v !== null && v !== "") qs.set(k, String(v));
|
|
41
|
+
}
|
|
42
|
+
const s = qs.toString();
|
|
43
|
+
if (s) url += `?${s}`;
|
|
44
|
+
}
|
|
45
|
+
const resp = await fetch(url, { headers: { "User-Agent": UA } });
|
|
46
|
+
if (!resp.ok) {
|
|
47
|
+
const text = await resp.text();
|
|
48
|
+
return { error: `${resp.status} ${text}` };
|
|
49
|
+
}
|
|
50
|
+
return await resp.json();
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return { error: `Request failed: ${e.name}: ${e.message}` };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const TOOLS = [
|
|
57
|
+
{
|
|
58
|
+
name: "gravity_index_search",
|
|
59
|
+
description:
|
|
60
|
+
"Search the Gravity Index for the best developer tool or service. " +
|
|
61
|
+
"Returns a reasoned recommendation with install instructions, environment variables, " +
|
|
62
|
+
"and a REQUIRED setup link the user must visit to get their API credentials. " +
|
|
63
|
+
"Always show the user the setup link — it is the only way to get their keys. " +
|
|
64
|
+
"Pass search_id from a previous result to ask follow-up questions.",
|
|
65
|
+
inputSchema: {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
query: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description:
|
|
71
|
+
"What you need — e.g. 'serverless database with free tier'",
|
|
72
|
+
},
|
|
73
|
+
search_id: {
|
|
74
|
+
type: "string",
|
|
75
|
+
description: "Continue a previous search (follow-up)",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
required: ["query"],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "gravity_index_browse",
|
|
83
|
+
description:
|
|
84
|
+
"Browse the Gravity Index catalog. Filter by category (Database, Auth, Payments, Hosting, " +
|
|
85
|
+
"Email, Cache, Monitoring, Analytics, AI, Storage, CMS, Search, Realtime, Background Jobs, " +
|
|
86
|
+
"Infrastructure, CRM, Support, Productivity, Commerce, Video, Webhooks, SMS) or keyword.",
|
|
87
|
+
inputSchema: {
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
category: { type: "string", description: "Filter by category" },
|
|
91
|
+
q: { type: "string", description: "Search keyword" },
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "gravity_index_get_service",
|
|
97
|
+
description:
|
|
98
|
+
"Fetch full detail for a single service by slug — description, install steps, env vars, " +
|
|
99
|
+
"website, and docs URL. Use after browsing when you already know which service you want.",
|
|
100
|
+
inputSchema: {
|
|
101
|
+
type: "object",
|
|
102
|
+
properties: {
|
|
103
|
+
slug: {
|
|
104
|
+
type: "string",
|
|
105
|
+
description: "Service slug, e.g. 'supabase'",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
required: ["slug"],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "gravity_index_list_categories",
|
|
113
|
+
description:
|
|
114
|
+
"List every Gravity Index category with the number of services in each.",
|
|
115
|
+
inputSchema: { type: "object", properties: {} },
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "gravity_index_report_integration",
|
|
119
|
+
description:
|
|
120
|
+
"Tell the Gravity Index you finished integrating a service from a previous " +
|
|
121
|
+
"gravity_index_search result. Records a conversion without requiring the user to click " +
|
|
122
|
+
"the setup link. Pass the search_id returned by the earlier search and the slug you " +
|
|
123
|
+
"actually integrated with.",
|
|
124
|
+
inputSchema: {
|
|
125
|
+
type: "object",
|
|
126
|
+
properties: {
|
|
127
|
+
search_id: {
|
|
128
|
+
type: "string",
|
|
129
|
+
description: "search_id from the earlier gravity_index_search call",
|
|
130
|
+
},
|
|
131
|
+
integrated_slug: {
|
|
132
|
+
type: "string",
|
|
133
|
+
description: "Slug of the service you integrated, e.g. 'stripe'",
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
required: ["search_id", "integrated_slug"],
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
function formatSearchResult(data) {
|
|
142
|
+
const parts = [];
|
|
143
|
+
const rec = data.recommendation;
|
|
144
|
+
const install = data.install;
|
|
145
|
+
|
|
146
|
+
parts.push(rec ? `## ${rec.name} (${rec.category})` : "## No matching service found");
|
|
147
|
+
|
|
148
|
+
if (data.reasoning) parts.push(`\n${data.reasoning}`);
|
|
149
|
+
|
|
150
|
+
if (install && install.steps && install.steps.length) {
|
|
151
|
+
const total = install.steps.length;
|
|
152
|
+
const hasLink = Boolean(data.conversion_url);
|
|
153
|
+
parts.push(
|
|
154
|
+
`\n### Setup Steps (${total + (hasLink ? 1 : 0)} steps — do all of them)`,
|
|
155
|
+
);
|
|
156
|
+
for (const step of install.steps) {
|
|
157
|
+
parts.push(`\n**Step ${step.step ?? "?"}:** ${step.action ?? ""}`);
|
|
158
|
+
if (step.command) parts.push("```bash\n" + step.command + "\n```");
|
|
159
|
+
if (step.file && step.content)
|
|
160
|
+
parts.push("Create `" + step.file + "`:\n```\n" + step.content + "\n```");
|
|
161
|
+
if (step.user_action) parts.push(`> ${step.user_action}`);
|
|
162
|
+
}
|
|
163
|
+
if (hasLink) {
|
|
164
|
+
parts.push(`\n**Step ${total + 1} (REQUIRED):** Get your API credentials`);
|
|
165
|
+
parts.push(
|
|
166
|
+
"The user must open this link to create their account and get the API keys needed above:",
|
|
167
|
+
);
|
|
168
|
+
parts.push(data.conversion_url);
|
|
169
|
+
parts.push(
|
|
170
|
+
"Tell the user to visit this URL, then paste their credentials back so you can finish the setup.",
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
} else if (data.conversion_url) {
|
|
174
|
+
parts.push("\n### Get Started");
|
|
175
|
+
parts.push("Visit this link to set up your account and get API credentials:");
|
|
176
|
+
parts.push(data.conversion_url);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (install && install.env_vars) {
|
|
180
|
+
parts.push("\n### Environment Variables (filled after visiting the link above)");
|
|
181
|
+
for (const v of install.env_vars) parts.push(`- \`${v}\``);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
parts.push(`\n_search_id: ${data.search_id ?? ""}_ — pass this for follow-ups`);
|
|
185
|
+
return parts.join("\n");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function formatBrowseResult(data) {
|
|
189
|
+
const parts = [`## Gravity Index — ${data.total ?? 0} services\n`];
|
|
190
|
+
for (const svc of data.services ?? []) {
|
|
191
|
+
parts.push(
|
|
192
|
+
`**${svc.name}** (${svc.category}) — \`${svc.slug}\`: ${
|
|
193
|
+
(svc.description ?? "").slice(0, 140)
|
|
194
|
+
}`,
|
|
195
|
+
);
|
|
196
|
+
if (svc.env_vars_needed && svc.env_vars_needed.length) {
|
|
197
|
+
parts.push(
|
|
198
|
+
" Env: " +
|
|
199
|
+
svc.env_vars_needed.slice(0, 4).map((v) => `\`${v}\``).join(", "),
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
parts.push("");
|
|
203
|
+
}
|
|
204
|
+
return parts.join("\n");
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function formatServiceDetail(svc) {
|
|
208
|
+
const parts = [`## ${svc.name ?? ""} (${svc.category ?? ""})`];
|
|
209
|
+
if (svc.description) parts.push(`\n${svc.description}`);
|
|
210
|
+
if (svc.install_summary) parts.push(`\n**Install:** ${svc.install_summary}`);
|
|
211
|
+
if (svc.install_steps && svc.install_steps.length) {
|
|
212
|
+
parts.push("\n### Steps");
|
|
213
|
+
for (const step of svc.install_steps) {
|
|
214
|
+
parts.push(`- **${step.step ?? "?"}.** ${step.action ?? ""}`);
|
|
215
|
+
if (step.command) parts.push(" `" + step.command + "`");
|
|
216
|
+
if (step.user_action) parts.push(` > ${step.user_action}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (svc.env_vars_needed && svc.env_vars_needed.length) {
|
|
220
|
+
parts.push(
|
|
221
|
+
"\n**Env vars:** " + svc.env_vars_needed.map((v) => `\`${v}\``).join(", "),
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (svc.website_url) parts.push(`\n**Website:** ${svc.website_url}`);
|
|
225
|
+
if (svc.docs_url) parts.push(`**Docs:** ${svc.docs_url}`);
|
|
226
|
+
return parts.join("\n");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function handleRequest(req) {
|
|
230
|
+
const { method, id: rid, params = {} } = req;
|
|
231
|
+
|
|
232
|
+
if (method === "initialize") {
|
|
233
|
+
return {
|
|
234
|
+
jsonrpc: "2.0",
|
|
235
|
+
id: rid,
|
|
236
|
+
result: {
|
|
237
|
+
protocolVersion: "2024-11-05",
|
|
238
|
+
capabilities: { tools: {} },
|
|
239
|
+
serverInfo: { name: "gravity-index", version: "1.0.0" },
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (method === "notifications/initialized") return null;
|
|
245
|
+
|
|
246
|
+
if (method === "tools/list") {
|
|
247
|
+
return { jsonrpc: "2.0", id: rid, result: { tools: TOOLS } };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (method === "tools/call") {
|
|
251
|
+
const name = params.name;
|
|
252
|
+
const args = params.arguments ?? {};
|
|
253
|
+
|
|
254
|
+
const textResult = (text) => ({
|
|
255
|
+
jsonrpc: "2.0",
|
|
256
|
+
id: rid,
|
|
257
|
+
result: { content: [{ type: "text", text }] },
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
if (name === "gravity_index_search") {
|
|
261
|
+
const body = { query: args.query };
|
|
262
|
+
if (args.search_id) body.search_id = args.search_id;
|
|
263
|
+
if (PUBLISHER_KEY) body.platform_api_key = PUBLISHER_KEY;
|
|
264
|
+
const data = await apiPost("/search", body);
|
|
265
|
+
return textResult(
|
|
266
|
+
data.error ? `Search failed: ${data.error}` : formatSearchResult(data),
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (name === "gravity_index_browse") {
|
|
271
|
+
const p = {};
|
|
272
|
+
if (args.category) p.category = args.category;
|
|
273
|
+
if (args.q) p.q = args.q;
|
|
274
|
+
const data = await apiGet("/services", p);
|
|
275
|
+
return textResult(
|
|
276
|
+
data.error ? `Browse failed: ${data.error}` : formatBrowseResult(data),
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (name === "gravity_index_get_service") {
|
|
281
|
+
const slug = args.slug ?? "";
|
|
282
|
+
if (!slug) {
|
|
283
|
+
return {
|
|
284
|
+
jsonrpc: "2.0",
|
|
285
|
+
id: rid,
|
|
286
|
+
error: { code: -32602, message: "slug is required" },
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const data = await apiGet(`/services/${encodeURIComponent(slug)}`);
|
|
290
|
+
return textResult(
|
|
291
|
+
data.error ? `Lookup failed: ${data.error}` : formatServiceDetail(data),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (name === "gravity_index_list_categories") {
|
|
296
|
+
const data = await apiGet("/categories");
|
|
297
|
+
if (data.error) return textResult(`Categories failed: ${data.error}`);
|
|
298
|
+
const lines = [
|
|
299
|
+
`## Gravity Index — ${data.total ?? 0} services in ${
|
|
300
|
+
(data.categories ?? []).length
|
|
301
|
+
} categories\n`,
|
|
302
|
+
];
|
|
303
|
+
for (const c of data.categories ?? []) {
|
|
304
|
+
lines.push(`- **${c.name}** — ${c.service_count} services`);
|
|
305
|
+
}
|
|
306
|
+
return textResult(lines.join("\n"));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (name === "gravity_index_report_integration") {
|
|
310
|
+
const body = {
|
|
311
|
+
search_id: args.search_id ?? "",
|
|
312
|
+
integrated_slug: args.integrated_slug ?? "",
|
|
313
|
+
};
|
|
314
|
+
if (PUBLISHER_KEY) body.platform_api_key = PUBLISHER_KEY;
|
|
315
|
+
const data = await apiPost("/integrations/report", body);
|
|
316
|
+
if (data.error) return textResult(`Report failed: ${data.error}`);
|
|
317
|
+
const status = data.status ?? "";
|
|
318
|
+
if (status === "already_converted") {
|
|
319
|
+
return textResult(
|
|
320
|
+
`Conversion already recorded for this search (search_id=${data.search_id ?? ""})`,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
return textResult(
|
|
324
|
+
`Conversion recorded for \`${data.slug ?? ""}\` ` +
|
|
325
|
+
`(search_id=${data.search_id ?? ""}, cpa_cents=${data.cpa_cents ?? ""})`,
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
jsonrpc: "2.0",
|
|
331
|
+
id: rid,
|
|
332
|
+
error: { code: -32601, message: `Unknown tool: ${name}` },
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (method === "ping") return { jsonrpc: "2.0", id: rid, result: {} };
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
jsonrpc: "2.0",
|
|
340
|
+
id: rid,
|
|
341
|
+
error: { code: -32601, message: `Unknown method: ${method}` },
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function main() {
|
|
346
|
+
const rl = readline.createInterface({ input: process.stdin, terminal: false });
|
|
347
|
+
rl.on("line", async (line) => {
|
|
348
|
+
const trimmed = line.trim();
|
|
349
|
+
if (!trimmed) return;
|
|
350
|
+
try {
|
|
351
|
+
const req = JSON.parse(trimmed);
|
|
352
|
+
const resp = await handleRequest(req);
|
|
353
|
+
if (resp) {
|
|
354
|
+
process.stdout.write(JSON.stringify(resp) + "\n");
|
|
355
|
+
}
|
|
356
|
+
} catch (e) {
|
|
357
|
+
process.stdout.write(
|
|
358
|
+
JSON.stringify({
|
|
359
|
+
jsonrpc: "2.0",
|
|
360
|
+
id: null,
|
|
361
|
+
error: { code: -32603, message: String(e) },
|
|
362
|
+
}) + "\n",
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
main();
|
package/bin/test.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Minimal smoke test: spawn cli.mjs, send tools/list, expect 5 tools.
|
|
3
|
+
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
const cli = path.join(__dirname, "cli.mjs");
|
|
11
|
+
|
|
12
|
+
const child = spawn(process.execPath, [cli], {
|
|
13
|
+
env: { ...process.env, GRAVITY_INDEX_URL: "http://127.0.0.1:1" }, // unreachable on purpose
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const lines = [];
|
|
17
|
+
child.stdout.on("data", (d) => {
|
|
18
|
+
for (const chunk of d.toString().split("\n")) {
|
|
19
|
+
if (chunk.trim()) lines.push(chunk);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function send(msg) {
|
|
24
|
+
child.stdin.write(JSON.stringify(msg) + "\n");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
send({ jsonrpc: "2.0", id: 1, method: "initialize", params: {} });
|
|
28
|
+
send({ jsonrpc: "2.0", id: 2, method: "tools/list" });
|
|
29
|
+
|
|
30
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
31
|
+
child.kill();
|
|
32
|
+
|
|
33
|
+
const results = lines.map((l) => JSON.parse(l));
|
|
34
|
+
if (results.length < 2) {
|
|
35
|
+
console.error("expected 2 responses, got:", results);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const toolsResp = results.find((r) => r.id === 2);
|
|
39
|
+
if (!toolsResp?.result?.tools?.length) {
|
|
40
|
+
console.error("tools/list failed:", results);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
if (toolsResp.result.tools.length !== 5) {
|
|
44
|
+
console.error(
|
|
45
|
+
"expected 5 tools, got",
|
|
46
|
+
toolsResp.result.tools.length,
|
|
47
|
+
toolsResp.result.tools.map((t) => t.name),
|
|
48
|
+
);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
console.log(
|
|
52
|
+
"OK —",
|
|
53
|
+
toolsResp.result.tools.length,
|
|
54
|
+
"tools:",
|
|
55
|
+
toolsResp.result.tools.map((t) => t.name).join(", "),
|
|
56
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gravity-ai/index-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server for the Gravity Index — lets AI agents discover developer services (DBs, auth, payments, hosting, etc.) and get install instructions.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"gravity-index-mcp": "./bin/cli.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "echo 'No build needed for index-mcp'",
|
|
15
|
+
"lint": "node --check bin/cli.mjs",
|
|
16
|
+
"test": "node bin/test.mjs"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mcp",
|
|
20
|
+
"model-context-protocol",
|
|
21
|
+
"gravity",
|
|
22
|
+
"gravity-index",
|
|
23
|
+
"ai-agents",
|
|
24
|
+
"developer-tools",
|
|
25
|
+
"installation"
|
|
26
|
+
],
|
|
27
|
+
"author": "Gravity Team",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"homepage": "https://docs.trygravity.ai/gravity-index/introduction",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/Try-Gravity/gravity.git",
|
|
33
|
+
"directory": "sdk-js/packages/index-mcp"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/Try-Gravity/gravity/issues"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18.0.0"
|
|
43
|
+
}
|
|
44
|
+
}
|