@indigoai/mcp-companion 0.1.2 → 0.2.1
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 +10 -4
- package/dist/companion.js +18 -4
- package/dist/flavours.js +4 -1
- package/dist/remote.js +34 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ The local MCP server that connects Claude to every indigo.ai environment a perso
|
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
-
Every release ships two builds from the same commit. The production one is for everyone. The staging one connects only staging environments and is for the staff.
|
|
7
|
+
Every release ships two builds from the same commit. The production one is for everyone. The staging one connects only staging environments and is for the staff. Install with `@latest`: each new session then starts the latest release, so a new release reaches everyone at their next session with nothing to reinstall. Pin an exact version (`@X.Y.Z`, the release tag without its `v`) only to hold a machine on a known release.
|
|
8
8
|
|
|
9
9
|
| | Production | Staging |
|
|
10
10
|
|---|---|---|
|
|
@@ -12,14 +12,20 @@ Every release ships two builds from the same commit. The production one is for e
|
|
|
12
12
|
| Claude Desktop bundle | `indigo-mcp-companion.mcpb` | `indigo-mcp-companion-staging.mcpb` |
|
|
13
13
|
| Directory | `https://mcp.indigo.ai` | `https://staging.mcp.indigo.ai` |
|
|
14
14
|
|
|
15
|
-
- **Claude
|
|
16
|
-
- **Claude
|
|
15
|
+
- **Claude Code:** `claude mcp add --scope user indigo -- npx -y @indigoai/mcp-companion@latest` (on Windows: `claude mcp add --scope user indigo -- cmd /c npx -y @indigoai/mcp-companion@latest`). For staging: `claude mcp add --scope user indigo-staging -- npx -y @indigoai/mcp-companion-staging@latest`.
|
|
16
|
+
- **Claude Desktop:** in Settings → Developer → Edit Config, add the server to `mcpServers` in `claude_desktop_config.json`, then restart Claude Desktop. If it cannot find `npx`, set `command` to the full path `which npx` prints.
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{ "mcpServers": { "indigo": { "command": "npx", "args": ["-y", "@indigoai/mcp-companion@latest"] } } }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The `mcpb` jobs still build a signed bundle per release, but it is not distributed for now.
|
|
17
23
|
- **Codex:** in `~/.codex/config.toml`
|
|
18
24
|
|
|
19
25
|
```toml
|
|
20
26
|
[mcp_servers.indigo]
|
|
21
27
|
command = "npx"
|
|
22
|
-
args = ["-y", "@indigoai/mcp-companion@
|
|
28
|
+
args = ["-y", "@indigoai/mcp-companion@latest"]
|
|
23
29
|
```
|
|
24
30
|
|
|
25
31
|
## How it works
|
package/dist/companion.js
CHANGED
|
@@ -5,9 +5,12 @@ import { verifyDescriptor } from "./descriptors.js";
|
|
|
5
5
|
import { grantAccount, Grants, NeedsReconnect } from "./grants.js";
|
|
6
6
|
import { startLoopback } from "./loopback.js";
|
|
7
7
|
import { authorizeUrl, checkPlatformMetadata, exchangeDirectoryCode, exchangePlatformCode, HttpError, OAuthError, revokePlatformToken, } from "./oauth.js";
|
|
8
|
-
import {
|
|
8
|
+
import { Remotes } from "./remote.js";
|
|
9
9
|
import { loadState, saveState } from "./state.js";
|
|
10
10
|
const EMAIL_PROOF = "directory-email-proof";
|
|
11
|
+
// The catalog says which tools only read, which is what keeps a write out of run_read_tool, so a
|
|
12
|
+
// cached one is never trusted for long.
|
|
13
|
+
const CATALOG_TTL_MS = 10 * 60_000;
|
|
11
14
|
function reachable(d, error) {
|
|
12
15
|
if (error.message !== "fetch failed")
|
|
13
16
|
return error;
|
|
@@ -22,6 +25,8 @@ export class Companion {
|
|
|
22
25
|
grants;
|
|
23
26
|
notice = null;
|
|
24
27
|
discovering = null;
|
|
28
|
+
remotes = new Remotes();
|
|
29
|
+
catalogs = new Map();
|
|
25
30
|
constructor(opts) {
|
|
26
31
|
this.opts = opts;
|
|
27
32
|
this.grants = new Grants(opts.keychain, join(opts.dir, "locks"));
|
|
@@ -170,7 +175,7 @@ export class Companion {
|
|
|
170
175
|
}
|
|
171
176
|
async describeTools(environmentId) {
|
|
172
177
|
const d = this.descriptor(environmentId);
|
|
173
|
-
const tools = await this.call(d,
|
|
178
|
+
const tools = await this.call(d, (client) => this.catalog(d, client, true));
|
|
174
179
|
return JSON.stringify(tools.map((t) => ({
|
|
175
180
|
name: t.name,
|
|
176
181
|
access: t.annotations?.readOnlyHint === true ? "read" : "write",
|
|
@@ -181,7 +186,8 @@ export class Companion {
|
|
|
181
186
|
async runTool(environmentId, tool, args, access) {
|
|
182
187
|
const d = this.descriptor(environmentId);
|
|
183
188
|
return this.call(d, async (client) => {
|
|
184
|
-
const
|
|
189
|
+
const named = (tools) => tools.find((t) => t.name === tool);
|
|
190
|
+
const found = named(await this.catalog(d, client)) ?? named(await this.catalog(d, client, true));
|
|
185
191
|
if (!found)
|
|
186
192
|
throw new Error(`${d.label} has no tool named ${tool}`);
|
|
187
193
|
const isRead = found.annotations?.readOnlyHint === true;
|
|
@@ -192,6 +198,14 @@ export class Companion {
|
|
|
192
198
|
return client.callTool({ name: tool, arguments: args });
|
|
193
199
|
});
|
|
194
200
|
}
|
|
201
|
+
async catalog(d, client, fresh = false) {
|
|
202
|
+
const cached = this.catalogs.get(d.mcp_resource);
|
|
203
|
+
if (!fresh && cached && Date.now() - cached.readAt < CATALOG_TTL_MS)
|
|
204
|
+
return cached.tools;
|
|
205
|
+
const tools = (await client.listTools()).tools;
|
|
206
|
+
this.catalogs.set(d.mcp_resource, { tools, readAt: Date.now() });
|
|
207
|
+
return tools;
|
|
208
|
+
}
|
|
195
209
|
async call(d, fn) {
|
|
196
210
|
const connection = loadState(this.opts.dir).connections[d.environment_id];
|
|
197
211
|
if (connection?.status !== "connected") {
|
|
@@ -201,7 +215,7 @@ export class Companion {
|
|
|
201
215
|
throw new Error(`${d.label} moved to another address: disconnect it, then connect it again`);
|
|
202
216
|
}
|
|
203
217
|
try {
|
|
204
|
-
const result = await
|
|
218
|
+
const result = await this.remotes.with(grantAccount(connection), d.mcp_resource, (force) => this.grants.accessToken(d, connection, force), fn);
|
|
205
219
|
const environment = result?._meta?.environment;
|
|
206
220
|
if (environment !== undefined && environment !== d.issuer) {
|
|
207
221
|
throw new Error(`the answer came from ${String(environment)}, not from ${d.label}`);
|
package/dist/flavours.js
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
export const production = {
|
|
5
5
|
name: "indigo-mcp-companion",
|
|
6
6
|
directoryUrl: "https://mcp.indigo.ai",
|
|
7
|
-
descriptorKey:
|
|
7
|
+
descriptorKey: `-----BEGIN PUBLIC KEY-----
|
|
8
|
+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEau34ATCF+pyJpQryYFXrMVLxDHlN
|
|
9
|
+
WnsQkCqV+OSII405PMwA+pqn/P8JX3g0zq7un483p16q08JoJ1F/EZFNzw==
|
|
10
|
+
-----END PUBLIC KEY-----`,
|
|
8
11
|
};
|
|
9
12
|
export const staging = {
|
|
10
13
|
name: "indigo-mcp-companion-staging",
|
package/dist/remote.js
CHANGED
|
@@ -1,23 +1,44 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
-
|
|
2
|
+
import { StreamableHTTPClientTransport, StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
+
// The platform serves one request at a time per MCP session, so a session is lent to one call at a
|
|
4
|
+
// time: concurrent calls open more, and each goes back to the pool when its call ends.
|
|
5
|
+
export class Remotes {
|
|
6
|
+
idle = new Map();
|
|
7
|
+
async with(key, resource, token, fn) {
|
|
8
|
+
const pool = this.idle.get(key) ?? this.idle.set(key, []).get(key);
|
|
9
|
+
let session = pool.pop() ?? (await open(resource, token));
|
|
10
|
+
session.token = token;
|
|
11
|
+
try {
|
|
12
|
+
const result = await fn(session.client).catch(async (error) => {
|
|
13
|
+
// A session the server no longer knows is refused before anything runs, so the call is
|
|
14
|
+
// safe to send again on a new one.
|
|
15
|
+
if (!(error instanceof StreamableHTTPError && error.code === 404))
|
|
16
|
+
throw error;
|
|
17
|
+
await session.client.close();
|
|
18
|
+
session = await open(resource, token);
|
|
19
|
+
return fn(session.client);
|
|
20
|
+
});
|
|
21
|
+
pool.push(session);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
await session.client.close();
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function open(resource, token) {
|
|
31
|
+
const client = new Client({ name: "indigo-mcp-companion", version: "0.1.0" });
|
|
32
|
+
const session = { client, token };
|
|
4
33
|
const authFetch = async (url, init) => {
|
|
5
34
|
const send = async (force) => {
|
|
6
35
|
const headers = new Headers(init?.headers);
|
|
7
|
-
headers.set("authorization", `Bearer ${await token(force)}`);
|
|
36
|
+
headers.set("authorization", `Bearer ${await session.token(force)}`);
|
|
8
37
|
return fetch(url, { ...init, headers, redirect: "error" });
|
|
9
38
|
};
|
|
10
39
|
const res = await send(false);
|
|
11
40
|
return res.status === 401 ? send(true) : res;
|
|
12
41
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
await client.connect(transport);
|
|
16
|
-
try {
|
|
17
|
-
return await fn(client);
|
|
18
|
-
}
|
|
19
|
-
finally {
|
|
20
|
-
await transport.terminateSession().catch(() => { });
|
|
21
|
-
await client.close();
|
|
22
|
-
}
|
|
42
|
+
await client.connect(new StreamableHTTPClientTransport(new URL(resource), { fetch: authFetch }));
|
|
43
|
+
return session;
|
|
23
44
|
}
|