@stage-labs/metro 0.1.0-beta.292 → 0.1.0-beta.294

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.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/runtime/marketplace/plugin/.claude-plugin/plugin.json +1 -1
  3. package/runtime/marketplace/plugin/bin/policy.mjs +4 -1
  4. package/runtime/node_modules/@metro-labs/daemon/src/connectors/gates.ts +27 -23
  5. package/runtime/node_modules/@metro-labs/daemon/src/connectors/migration-control.ts +7 -3
  6. package/runtime/node_modules/@metro-labs/daemon/src/connectors/migration-guard.ts +12 -9
  7. package/runtime/node_modules/@metro-labs/daemon/src/connectors/migration-operations.ts +20 -0
  8. package/runtime/node_modules/@metro-labs/daemon/src/connectors/migration-preview.ts +4 -6
  9. package/runtime/node_modules/@metro-labs/daemon/src/connectors/oauth-routes.ts +2 -2
  10. package/runtime/node_modules/@metro-labs/daemon/src/connectors/org-runtime-discovery.ts +3 -3
  11. package/runtime/node_modules/@metro-labs/daemon/src/connectors/org-runtime.ts +12 -6
  12. package/runtime/node_modules/@metro-labs/daemon/src/connectors/org-sync-control.ts +16 -3
  13. package/runtime/node_modules/@metro-labs/daemon/src/connectors/org-sync-watch.ts +1 -1
  14. package/runtime/node_modules/@metro-labs/daemon/src/connectors/org-sync.ts +8 -1
  15. package/runtime/node_modules/@metro-labs/daemon/src/connectors/plugin-sync.ts +39 -12
  16. package/runtime/node_modules/@metro-labs/daemon/src/connectors/publication.ts +22 -11
  17. package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay-passive.ts +96 -0
  18. package/runtime/node_modules/@metro-labs/daemon/src/connectors/relay.ts +21 -12
  19. package/runtime/node_modules/@metro-labs/daemon/src/connectors/server-keys.ts +46 -0
  20. package/runtime/node_modules/@metro-labs/daemon/src/connectors/store.ts +10 -15
  21. package/runtime/node_modules/@metro-labs/daemon/src/connectors/tools.ts +1 -85
  22. package/runtime/node_modules/@metro-labs/daemon/src/connectors/transfer-store.ts +1 -4
  23. package/runtime/node_modules/@metro-labs/daemon/src/mcp/permission-prompt.ts +6 -2
  24. package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-gate.ts +1 -2
  25. package/runtime/node_modules/@metro-labs/http/package.json +1 -0
  26. package/runtime/node_modules/@metro-labs/http/src/connector-delivery-validation.ts +4 -3
  27. package/runtime/node_modules/@metro-labs/http/src/connector-delivery.ts +2 -2
  28. package/runtime/node_modules/@metro-labs/http/src/connector-policy.ts +39 -3
  29. package/runtime/node_modules/@metro-labs/http/src/connector-tools.ts +94 -0
  30. package/runtime/runtime.json +1 -1
  31. package/runtime/sdk-runner/runner.json +1 -1
@@ -0,0 +1,94 @@
1
+ import { isRecord } from '@metro-labs/core/is-record';
2
+ import { errMsg, log } from '@metro-labs/core/log';
3
+ import type { FetchLike } from '@metro-labs/core/stations/oauth';
4
+ import { authHeaders, INITIALIZE, mcpPost, payloadOf, type ConnectorAuth } from './connector-mcp.js';
5
+ import { ConnectorUnauthorized, refused } from './connector-url.js';
6
+
7
+ export interface RemoteTool {
8
+ name: string;
9
+ title: string;
10
+ description: string;
11
+ readOnly: boolean;
12
+ }
13
+
14
+ const TIMEOUT_MS = 15_000;
15
+ const MAX_PAGES = 100;
16
+ const MAX_TOOLS = 2000;
17
+
18
+ function resultOf(text: string, contentType: string): Record<string, unknown> | null {
19
+ let parsed: unknown = null;
20
+ try {
21
+ parsed = JSON.parse(payloadOf(text, contentType));
22
+ } catch {
23
+ return null;
24
+ }
25
+ return isRecord(parsed) && isRecord(parsed.result) ? parsed.result : null;
26
+ }
27
+
28
+ async function rpc(url: URL, auth: ConnectorAuth, session: Map<string, string>, body: unknown, fetchImpl?: FetchLike): Promise<Record<string, unknown> | null> {
29
+ const res = await mcpPost(url, auth, body, { timeoutMs: TIMEOUT_MS, headers: Object.fromEntries(session), fetch: fetchImpl });
30
+ const id = res.headers.get('mcp-session-id');
31
+ if (id !== null && id !== '') session.set('mcp-session-id', id);
32
+ const text = await res.text().catch(() => '');
33
+ if (res.status === 401 || res.status === 403) throw new ConnectorUnauthorized(`${url.hostname} rejected the credential; connect it again`, 400);
34
+ if (!res.ok) throw refused(`${url.hostname} answered ${String(res.status)}`);
35
+ return resultOf(text, res.headers.get('content-type') ?? '');
36
+ }
37
+
38
+ function toTool(raw: unknown): RemoteTool | null {
39
+ if (!isRecord(raw) || typeof raw.name !== 'string') return null;
40
+ const annotations = isRecord(raw.annotations) ? raw.annotations : {};
41
+ const title = typeof raw.title === 'string' && raw.title !== '' ? raw.title : raw.name;
42
+ return { name: raw.name, title, description: typeof raw.description === 'string' ? raw.description : '', readOnly: annotations.readOnlyHint === true };
43
+ }
44
+
45
+ async function endSession(url: URL, auth: ConnectorAuth, session: Map<string, string>, fetchImpl?: FetchLike): Promise<void> {
46
+ if (!session.has('mcp-session-id')) return;
47
+ try {
48
+ const send = fetchImpl ?? fetch;
49
+ const res = await send(url.toString(), { method: 'DELETE', redirect: 'manual', signal: AbortSignal.timeout(TIMEOUT_MS), headers: { ...authHeaders(auth), ...Object.fromEntries(session) } });
50
+ if (res.ok) await res.body?.pipeTo(new WritableStream<Uint8Array>());
51
+ else await res.body?.cancel();
52
+ } catch (err) {
53
+ log.debug(fetchImpl === undefined ? { host: url.hostname, err: errMsg(err) } : {}, 'connector-tools: the remote declined to end the session');
54
+ }
55
+ }
56
+
57
+ function addTools(result: Record<string, unknown> | null, tools: Map<string, RemoteTool>): unknown {
58
+ if (result === null || !Array.isArray(result.tools)) throw refused('The provider did not return a complete tool list.');
59
+ for (const raw of result.tools) {
60
+ const tool = toTool(raw);
61
+ if (tool === null || tools.has(tool.name)) throw refused('The provider returned an invalid tool list.');
62
+ tools.set(tool.name, tool);
63
+ if (tools.size > MAX_TOOLS) throw refused('The provider returned too many tools.');
64
+ }
65
+ return result.nextCursor;
66
+ }
67
+
68
+ async function walkTools(url: URL, auth: ConnectorAuth, session: Map<string, string>, fetchImpl?: FetchLike): Promise<RemoteTool[]> {
69
+ const tools = new Map<string, RemoteTool>();
70
+ const cursors = new Set<string>();
71
+ let cursor = '';
72
+ for (let page = 0; page < MAX_PAGES; page += 1) {
73
+ const result = await rpc(url, auth, session, { jsonrpc: '2.0', id: 2 + page, method: 'tools/list', params: cursor === '' ? {} : { cursor } }, fetchImpl);
74
+ const next = addTools(result, tools);
75
+ if (next === undefined || next === null || next === '') return [...tools.values()];
76
+ if (typeof next !== 'string' || cursors.has(next)) throw refused('The provider did not return a complete tool list.');
77
+ cursors.add(next);
78
+ cursor = next;
79
+ }
80
+ throw refused('The provider did not return a complete tool list.');
81
+ }
82
+
83
+ export async function listRemoteTools(url: URL, auth: ConnectorAuth, fetchImpl?: FetchLike): Promise<RemoteTool[]> {
84
+ const session = new Map<string, string>();
85
+ try {
86
+ const init = await rpc(url, auth, session, INITIALIZE, fetchImpl);
87
+ if (init === null || typeof init.protocolVersion !== 'string') throw refused(`${url.hostname} answered, but it does not speak MCP.`);
88
+ session.set('mcp-protocol-version', init.protocolVersion);
89
+ await rpc(url, auth, session, { jsonrpc: '2.0', method: 'notifications/initialized' }, fetchImpl);
90
+ return await walkTools(url, auth, session, fetchImpl);
91
+ } finally {
92
+ await endSession(url, auth, session, fetchImpl);
93
+ }
94
+ }
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.1.0-beta.292"
2
+ "version": "0.1.0-beta.294"
3
3
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.0-beta.292",
2
+ "version": "0.1.0-beta.294",
3
3
  "dependencies": {
4
4
  "@anthropic-ai/claude-agent-sdk": "0.3.287",
5
5
  "@modelcontextprotocol/sdk": "^1.29.0",