-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscover.ts
More file actions
54 lines (49 loc) · 1.56 KB
/
Copy pathdiscover.ts
File metadata and controls
54 lines (49 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* MCP REST discover helpers (not JSON-RPC execute).
* Genetic tag: repo.tooling.user_cli.gen1 · repo.platform.sdk.gen1
*/
import { resolvePublicOrigin } from './urls';
export interface McpDiscoverOptions {
apiBase: string;
token: string;
projectId?: number;
}
async function mcpRestJson(
apiBase: string,
path: string,
init: RequestInit,
opts: McpDiscoverOptions,
): Promise<unknown> {
const origin = resolvePublicOrigin(apiBase);
const headers: Record<string, string> = {
Authorization: `Bearer ${opts.token}`,
...(init.headers as Record<string, string> | undefined),
};
if (opts.projectId != null && !headers['X-Project-ID']) {
headers['X-Project-ID'] = String(opts.projectId);
}
const res = await fetch(`${origin}${path}`, { ...init, headers });
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(JSON.stringify(data));
return data;
}
/** POST /mcp/discover/by_intent — intent → ranked MCP actions. */
export async function mcpDiscoverByIntent(
intent: string,
opts: McpDiscoverOptions & { projectId: number },
): Promise<unknown> {
return mcpRestJson(
opts.apiBase,
'/mcp/discover/by_intent',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ intent, project_id: opts.projectId }),
},
opts,
);
}
/** GET /mcp/discovery — API key capability context. */
export async function mcpGetDiscovery(opts: McpDiscoverOptions): Promise<unknown> {
return mcpRestJson(opts.apiBase, '/mcp/discovery', { method: 'GET' }, opts);
}