mcp-orbit 0.1.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/LICENSE +21 -0
- package/README.md +247 -0
- package/dist/__tests__/helpers/test-server.d.ts +2 -0
- package/dist/__tests__/helpers/test-server.d.ts.map +1 -0
- package/dist/__tests__/helpers/test-server.js +27 -0
- package/dist/__tests__/helpers/test-server.js.map +1 -0
- package/dist/cli.d.ts +23 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +56 -0
- package/dist/cli.js.map +1 -0
- package/dist/clients/mcp-http.d.ts +36 -0
- package/dist/clients/mcp-http.d.ts.map +1 -0
- package/dist/clients/mcp-http.js +148 -0
- package/dist/clients/mcp-http.js.map +1 -0
- package/dist/clients/mcp-stdio.d.ts +38 -0
- package/dist/clients/mcp-stdio.d.ts.map +1 -0
- package/dist/clients/mcp-stdio.js +164 -0
- package/dist/clients/mcp-stdio.js.map +1 -0
- package/dist/clients/types.d.ts +104 -0
- package/dist/clients/types.d.ts.map +1 -0
- package/dist/clients/types.js +8 -0
- package/dist/clients/types.js.map +1 -0
- package/dist/core/prompt-registry.d.ts +56 -0
- package/dist/core/prompt-registry.d.ts.map +1 -0
- package/dist/core/prompt-registry.js +100 -0
- package/dist/core/prompt-registry.js.map +1 -0
- package/dist/core/resource-registry.d.ts +79 -0
- package/dist/core/resource-registry.d.ts.map +1 -0
- package/dist/core/resource-registry.js +135 -0
- package/dist/core/resource-registry.js.map +1 -0
- package/dist/core/resource-uri-templates.d.ts +64 -0
- package/dist/core/resource-uri-templates.d.ts.map +1 -0
- package/dist/core/resource-uri-templates.js +168 -0
- package/dist/core/resource-uri-templates.js.map +1 -0
- package/dist/core/server-http.d.ts +15 -0
- package/dist/core/server-http.d.ts.map +1 -0
- package/dist/core/server-http.js +302 -0
- package/dist/core/server-http.js.map +1 -0
- package/dist/core/server-stdio.d.ts +8 -0
- package/dist/core/server-stdio.d.ts.map +1 -0
- package/dist/core/server-stdio.js +15 -0
- package/dist/core/server-stdio.js.map +1 -0
- package/dist/core/server.d.ts +29 -0
- package/dist/core/server.d.ts.map +1 -0
- package/dist/core/server.js +265 -0
- package/dist/core/server.js.map +1 -0
- package/dist/core/types.d.ts +265 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +9 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/dynamic-resource-manager.d.ts +115 -0
- package/dist/utils/dynamic-resource-manager.d.ts.map +1 -0
- package/dist/utils/dynamic-resource-manager.js +460 -0
- package/dist/utils/dynamic-resource-manager.js.map +1 -0
- package/dist/utils/http-client.d.ts +29 -0
- package/dist/utils/http-client.d.ts.map +1 -0
- package/dist/utils/http-client.js +59 -0
- package/dist/utils/http-client.js.map +1 -0
- package/dist/utils/logger.d.ts +25 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +105 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/zod-to-mcp-schema.d.ts +42 -0
- package/dist/utils/zod-to-mcp-schema.d.ts.map +1 -0
- package/dist/utils/zod-to-mcp-schema.js +87 -0
- package/dist/utils/zod-to-mcp-schema.js.map +1 -0
- package/package.json +57 -0
- package/src/__tests__/helpers/test-server.ts +31 -0
- package/src/__tests__/plugin-system.basic.test.ts +137 -0
- package/src/__tests__/server.basic.test.ts +37 -0
- package/src/__tests__/stdio-roundtrip.basic.test.ts +67 -0
- package/src/__tests__/tool-registry.basic.test.ts +114 -0
- package/src/__tests__/zod-schema.basic.test.ts +105 -0
- package/src/cli.ts +58 -0
- package/src/clients/mcp-http.ts +192 -0
- package/src/clients/mcp-stdio.ts +209 -0
- package/src/clients/types.ts +136 -0
- package/src/core/prompt-registry.ts +114 -0
- package/src/core/resource-registry.ts +166 -0
- package/src/core/resource-uri-templates.ts +216 -0
- package/src/core/server-http.ts +407 -0
- package/src/core/server-stdio.ts +20 -0
- package/src/core/server.ts +320 -0
- package/src/core/types.ts +312 -0
- package/src/index.ts +92 -0
- package/src/utils/dynamic-resource-manager.ts +581 -0
- package/src/utils/http-client.ts +86 -0
- package/src/utils/logger.ts +138 -0
- package/src/utils/zod-to-mcp-schema.ts +127 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stdio MCP Client
|
|
3
|
+
*
|
|
4
|
+
* Client for connecting to MCP servers via stdio (local child process)
|
|
5
|
+
* Features:
|
|
6
|
+
* - Client caching & connection pooling
|
|
7
|
+
* - Type-safe tool execution
|
|
8
|
+
* - Resource & Prompt management
|
|
9
|
+
*/
|
|
10
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
11
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
12
|
+
export class StdioMCPClient {
|
|
13
|
+
clientCache = new Map();
|
|
14
|
+
connectionPromises = new Map();
|
|
15
|
+
serverConfig;
|
|
16
|
+
// Event handlers (exposed from underlying MCP SDK Client)
|
|
17
|
+
onerror;
|
|
18
|
+
onclose;
|
|
19
|
+
constructor(serverConfig) {
|
|
20
|
+
this.serverConfig = serverConfig;
|
|
21
|
+
}
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// TOOLS
|
|
24
|
+
// ============================================================================
|
|
25
|
+
async listTools(timeoutMs = 15000) {
|
|
26
|
+
const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
|
|
27
|
+
const resp = (await client.listTools({}, { timeout: timeoutMs }));
|
|
28
|
+
const tools = Array.isArray(resp?.tools)
|
|
29
|
+
? resp.tools.map((tool) => ({
|
|
30
|
+
name: tool.name,
|
|
31
|
+
description: tool.description,
|
|
32
|
+
input_schema: tool.input_schema ?? tool.inputSchema ?? { type: "object", properties: {} },
|
|
33
|
+
tags: tool.tags ?? tool._meta?.tags,
|
|
34
|
+
}))
|
|
35
|
+
: [];
|
|
36
|
+
return { tools };
|
|
37
|
+
}
|
|
38
|
+
async callTool(toolName, args, timeoutMs = 15000) {
|
|
39
|
+
const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
|
|
40
|
+
const response = (await client.callTool({
|
|
41
|
+
name: toolName,
|
|
42
|
+
arguments: args,
|
|
43
|
+
}, undefined, { timeout: timeoutMs }));
|
|
44
|
+
return {
|
|
45
|
+
content: Array.isArray(response?.content) ? response.content : [],
|
|
46
|
+
isError: response?.isError ?? false,
|
|
47
|
+
structuredContent: response?.structuredContent,
|
|
48
|
+
_meta: response?._meta,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// RESOURCES
|
|
53
|
+
// ============================================================================
|
|
54
|
+
async listResources(timeoutMs = 15000) {
|
|
55
|
+
const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
|
|
56
|
+
const response = (await client.listResources({}, { timeout: timeoutMs }));
|
|
57
|
+
return {
|
|
58
|
+
resources: response.resources || [],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async readResource(uri, timeoutMs = 15000) {
|
|
62
|
+
const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
|
|
63
|
+
const response = (await client.readResource({ uri }, { timeout: timeoutMs }));
|
|
64
|
+
return {
|
|
65
|
+
contents: response.contents || [],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// PROMPTS
|
|
70
|
+
// ============================================================================
|
|
71
|
+
async listPrompts(timeoutMs = 15000) {
|
|
72
|
+
const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
|
|
73
|
+
const response = (await client.listPrompts({}, { timeout: timeoutMs }));
|
|
74
|
+
return {
|
|
75
|
+
prompts: response.prompts || [],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async getPrompt(name, args, timeoutMs = 15000) {
|
|
79
|
+
const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
|
|
80
|
+
const response = (await client.getPrompt({ name, arguments: args }, { timeout: timeoutMs }));
|
|
81
|
+
return {
|
|
82
|
+
messages: response.messages || [],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// ============================================================================
|
|
86
|
+
// PRIVATE HELPERS
|
|
87
|
+
// ============================================================================
|
|
88
|
+
/**
|
|
89
|
+
* Resolve environment variable placeholders like ${VAR_NAME}
|
|
90
|
+
* @param value - String that may contain placeholders
|
|
91
|
+
* @param env - Current environment variables to resolve from
|
|
92
|
+
* @returns Resolved string with placeholders replaced
|
|
93
|
+
*/
|
|
94
|
+
resolveEnvPlaceholders(value, env) {
|
|
95
|
+
return value.replace(/\$\{([^}]+)\}/g, (match, varName) => {
|
|
96
|
+
return env[varName] || match; // Replace with env value or keep placeholder if not found
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async createClient(server, timeoutMs) {
|
|
100
|
+
const client = new Client({ name: "mcp-orbit-client", version: "1.0.0" });
|
|
101
|
+
// Wire up event handlers from SDK Client to our wrapper
|
|
102
|
+
client.onerror = (error) => {
|
|
103
|
+
this.onerror?.(error);
|
|
104
|
+
};
|
|
105
|
+
client.onclose = () => {
|
|
106
|
+
this.onclose?.();
|
|
107
|
+
};
|
|
108
|
+
// Build env: start with current process.env, then overlay server.env
|
|
109
|
+
const env = {};
|
|
110
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
111
|
+
if (value !== undefined) {
|
|
112
|
+
env[key] = value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Resolve placeholders in server.env values
|
|
116
|
+
if (server.env) {
|
|
117
|
+
for (const [key, value] of Object.entries(server.env)) {
|
|
118
|
+
env[key] = this.resolveEnvPlaceholders(value, env);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const transport = new StdioClientTransport({
|
|
122
|
+
command: server.command,
|
|
123
|
+
args: server.args,
|
|
124
|
+
env,
|
|
125
|
+
cwd: server.cwd,
|
|
126
|
+
stderr: "pipe", // Use "pipe" instead of "inherit" for proper error event handling
|
|
127
|
+
});
|
|
128
|
+
await client.connect(transport, { timeout: timeoutMs });
|
|
129
|
+
return client;
|
|
130
|
+
}
|
|
131
|
+
async getOrCreateClient(server, timeoutMs) {
|
|
132
|
+
const key = this.getServerKey(server);
|
|
133
|
+
const existing = this.clientCache.get(key);
|
|
134
|
+
if (existing) {
|
|
135
|
+
return existing;
|
|
136
|
+
}
|
|
137
|
+
const pending = this.connectionPromises.get(key);
|
|
138
|
+
if (pending !== undefined) {
|
|
139
|
+
return pending;
|
|
140
|
+
}
|
|
141
|
+
const connectPromise = this.createClient(server, timeoutMs)
|
|
142
|
+
.then((client) => {
|
|
143
|
+
this.connectionPromises.delete(key);
|
|
144
|
+
this.clientCache.set(key, client);
|
|
145
|
+
return client;
|
|
146
|
+
})
|
|
147
|
+
.catch((error) => {
|
|
148
|
+
this.connectionPromises.delete(key);
|
|
149
|
+
throw error;
|
|
150
|
+
});
|
|
151
|
+
this.connectionPromises.set(key, connectPromise);
|
|
152
|
+
return connectPromise;
|
|
153
|
+
}
|
|
154
|
+
getServerKey(config) {
|
|
155
|
+
return `stdio:${config.command}:${config.args?.join(",")}`;
|
|
156
|
+
}
|
|
157
|
+
async close() {
|
|
158
|
+
const closePromises = Array.from(this.clientCache.values()).map((client) => client.close().catch(() => undefined));
|
|
159
|
+
this.clientCache.clear();
|
|
160
|
+
this.connectionPromises.clear();
|
|
161
|
+
await Promise.all(closePromises);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=mcp-stdio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-stdio.js","sourceRoot":"","sources":["../../src/clients/mcp-stdio.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAC,MAAM,EAAC,MAAM,2CAA2C,CAAC;AACjE,OAAO,EAAC,oBAAoB,EAAC,MAAM,2CAA2C,CAAC;AAY/E,MAAM,OAAO,cAAc;IACjB,WAAW,GA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C,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QACnH,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAChC,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Client Types & Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Shared types for mcp-orbit clients
|
|
5
|
+
* Used by both real clients and mock clients
|
|
6
|
+
*/
|
|
7
|
+
export interface McpStdioServerConfig {
|
|
8
|
+
command: string;
|
|
9
|
+
args?: string[];
|
|
10
|
+
env?: Record<string, string>;
|
|
11
|
+
cwd?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface McpHttpServerConfig {
|
|
14
|
+
url: string;
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
}
|
|
18
|
+
export type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;
|
|
19
|
+
export interface MCPToolSchema {
|
|
20
|
+
name: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
input_schema: {
|
|
23
|
+
type: "object";
|
|
24
|
+
properties?: Record<string, any>;
|
|
25
|
+
required?: string[];
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
28
|
+
tags?: string[];
|
|
29
|
+
}
|
|
30
|
+
export interface MCPToolResponse {
|
|
31
|
+
content: MCPContent[];
|
|
32
|
+
isError?: boolean;
|
|
33
|
+
structuredContent?: unknown;
|
|
34
|
+
_meta?: {
|
|
35
|
+
resourceUri?: string;
|
|
36
|
+
cached?: boolean;
|
|
37
|
+
size?: number;
|
|
38
|
+
cacheExpiry?: number;
|
|
39
|
+
toolName?: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface MCPContent {
|
|
43
|
+
type: "text" | "image" | "resource";
|
|
44
|
+
text?: string;
|
|
45
|
+
data?: string;
|
|
46
|
+
mimeType?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface MCPResource {
|
|
49
|
+
uri: string;
|
|
50
|
+
name: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
title?: string;
|
|
53
|
+
mimeType?: string;
|
|
54
|
+
toolset?: string;
|
|
55
|
+
scope?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface MCPResourceList {
|
|
58
|
+
resources: MCPResource[];
|
|
59
|
+
}
|
|
60
|
+
export interface MCPResourceContent {
|
|
61
|
+
contents: Array<{
|
|
62
|
+
uri: string;
|
|
63
|
+
text?: string;
|
|
64
|
+
blob?: string;
|
|
65
|
+
}>;
|
|
66
|
+
}
|
|
67
|
+
export interface MCPPromptArgument {
|
|
68
|
+
name: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
required?: boolean;
|
|
71
|
+
type?: "string" | "number" | "boolean" | "array" | "object";
|
|
72
|
+
}
|
|
73
|
+
export interface MCPPrompt {
|
|
74
|
+
name: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
arguments?: MCPPromptArgument[];
|
|
77
|
+
}
|
|
78
|
+
export interface MCPPromptList {
|
|
79
|
+
prompts: MCPPrompt[];
|
|
80
|
+
}
|
|
81
|
+
export interface MCPPromptMessage {
|
|
82
|
+
role: "user" | "assistant";
|
|
83
|
+
content: {
|
|
84
|
+
type: "text" | "image" | "resource";
|
|
85
|
+
text?: string;
|
|
86
|
+
data?: string;
|
|
87
|
+
mimeType?: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface MCPPromptResponse {
|
|
91
|
+
messages: MCPPromptMessage[];
|
|
92
|
+
}
|
|
93
|
+
export interface IMcpClient {
|
|
94
|
+
listTools(timeoutMs?: number): Promise<{
|
|
95
|
+
tools: MCPToolSchema[];
|
|
96
|
+
}>;
|
|
97
|
+
callTool(toolName: string, args: Record<string, any>, timeoutMs?: number): Promise<MCPToolResponse>;
|
|
98
|
+
listResources(timeoutMs?: number): Promise<MCPResourceList>;
|
|
99
|
+
readResource(uri: string, timeoutMs?: number): Promise<MCPResourceContent>;
|
|
100
|
+
listPrompts(timeoutMs?: number): Promise<MCPPromptList>;
|
|
101
|
+
getPrompt(name: string, args?: Record<string, any>, timeoutMs?: number): Promise<MCPPromptResponse>;
|
|
102
|
+
close(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/clients/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,eAAe,GAAG,oBAAoB,GAAG,mBAAmB,CAAC;AAMzE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACjC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,IAAI,CAAC,EAAE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AAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/clients/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Registry - Simplified
|
|
3
|
+
*
|
|
4
|
+
* Auto-registration pattern with direct array access.
|
|
5
|
+
*
|
|
6
|
+
* Prompts = Templated messages & workflows for users
|
|
7
|
+
* - Chat templates with variables
|
|
8
|
+
* - Workflow assistants
|
|
9
|
+
* - Guided interactions
|
|
10
|
+
*/
|
|
11
|
+
import type { MCPPromptDefinition, PromptProvider, PromptMessage } from "./types.js";
|
|
12
|
+
/**
|
|
13
|
+
* Create and register a prompt provider
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* const prompt = createAndRegisterPrompt({ name, description, render: async () => ({ messages }) });
|
|
17
|
+
*
|
|
18
|
+
* This function is called during prompt module imports (auto-registration pattern)
|
|
19
|
+
*/
|
|
20
|
+
export declare function createAndRegisterPrompt(prompt: PromptProvider): PromptProvider;
|
|
21
|
+
/**
|
|
22
|
+
* Get all prompt definitions (for MCP ListPrompts response)
|
|
23
|
+
*/
|
|
24
|
+
export declare function getPromptDefinitions(): MCPPromptDefinition[];
|
|
25
|
+
/**
|
|
26
|
+
* Get a prompt by name
|
|
27
|
+
*/
|
|
28
|
+
export declare function getPrompt(name: string): PromptProvider | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Get a prompt with rendered messages (prompts/get)
|
|
31
|
+
*
|
|
32
|
+
* Handles:
|
|
33
|
+
* - Prompt lookup
|
|
34
|
+
* - Arguments validation via Zod schema
|
|
35
|
+
* - Template rendering
|
|
36
|
+
*/
|
|
37
|
+
export declare function renderPrompt(name: string, args?: Record<string, any>): Promise<{
|
|
38
|
+
messages: PromptMessage[];
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Get count of registered prompts
|
|
42
|
+
*/
|
|
43
|
+
export declare function getPromptCount(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a prompt exists
|
|
46
|
+
*/
|
|
47
|
+
export declare function hasPrompt(name: string): boolean;
|
|
48
|
+
/** Singleton registry object — convenience wrapper over the named exports. */
|
|
49
|
+
export declare const promptRegistry: {
|
|
50
|
+
register: typeof createAndRegisterPrompt;
|
|
51
|
+
listDefinitions: typeof getPromptDefinitions;
|
|
52
|
+
get: typeof renderPrompt;
|
|
53
|
+
readonly count: number;
|
|
54
|
+
has: typeof hasPrompt;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=prompt-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-registry.d.ts","sourceRoot":"","sources":["../../src/core/prompt-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAC,mBAAmB,EAAE,cAAc,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAQnF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAQ9E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,mBAAmB,EAAE,CAW5D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAElE;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC;IAAC,QAAQ,EAAE,aAAa,EAAE,CAAA;CAAC,CAAC,CAoBjH;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,8EAA8E;AAC9E,eAAO,MAAM,cAAc;;;;oBAIZ,MAAM;;CAIpB,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Registry - Simplified
|
|
3
|
+
*
|
|
4
|
+
* Auto-registration pattern with direct array access.
|
|
5
|
+
*
|
|
6
|
+
* Prompts = Templated messages & workflows for users
|
|
7
|
+
* - Chat templates with variables
|
|
8
|
+
* - Workflow assistants
|
|
9
|
+
* - Guided interactions
|
|
10
|
+
*/
|
|
11
|
+
import logger from "../utils/logger.js";
|
|
12
|
+
const promptLogger = logger.child("prompts");
|
|
13
|
+
// Global prompts array - single source of truth
|
|
14
|
+
const prompts = [];
|
|
15
|
+
/**
|
|
16
|
+
* Create and register a prompt provider
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* const prompt = createAndRegisterPrompt({ name, description, render: async () => ({ messages }) });
|
|
20
|
+
*
|
|
21
|
+
* This function is called during prompt module imports (auto-registration pattern)
|
|
22
|
+
*/
|
|
23
|
+
export function createAndRegisterPrompt(prompt) {
|
|
24
|
+
if (prompts.some((p) => p.name === prompt.name)) {
|
|
25
|
+
promptLogger.warn(`Prompt '${prompt.name}' already registered, overwriting...`);
|
|
26
|
+
}
|
|
27
|
+
prompts.push(prompt);
|
|
28
|
+
promptLogger.info(`Prompt registered: ${prompt.name}`);
|
|
29
|
+
return prompt;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get all prompt definitions (for MCP ListPrompts response)
|
|
33
|
+
*/
|
|
34
|
+
export function getPromptDefinitions() {
|
|
35
|
+
return prompts.map((provider) => ({
|
|
36
|
+
name: provider.name,
|
|
37
|
+
description: provider.description,
|
|
38
|
+
arguments: provider.arguments,
|
|
39
|
+
toolset: provider.toolset,
|
|
40
|
+
tags: provider.tags,
|
|
41
|
+
category: provider.category,
|
|
42
|
+
usage: provider.usage,
|
|
43
|
+
maxTokens: provider.maxTokens,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get a prompt by name
|
|
48
|
+
*/
|
|
49
|
+
export function getPrompt(name) {
|
|
50
|
+
return prompts.find((p) => p.name === name);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get a prompt with rendered messages (prompts/get)
|
|
54
|
+
*
|
|
55
|
+
* Handles:
|
|
56
|
+
* - Prompt lookup
|
|
57
|
+
* - Arguments validation via Zod schema
|
|
58
|
+
* - Template rendering
|
|
59
|
+
*/
|
|
60
|
+
export async function renderPrompt(name, args) {
|
|
61
|
+
const prompt = getPrompt(name);
|
|
62
|
+
if (!prompt) {
|
|
63
|
+
throw new Error(`Prompt not found: ${name}`);
|
|
64
|
+
}
|
|
65
|
+
// Validate arguments if schema is provided
|
|
66
|
+
if (prompt.argumentsSchema && args) {
|
|
67
|
+
try {
|
|
68
|
+
prompt.argumentsSchema.parse(args);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new Error(`Invalid prompt arguments: ${String(error)}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Execute prompt provider (render template)
|
|
75
|
+
const messages = await prompt.render(args);
|
|
76
|
+
return { messages };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get count of registered prompts
|
|
80
|
+
*/
|
|
81
|
+
export function getPromptCount() {
|
|
82
|
+
return prompts.length;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if a prompt exists
|
|
86
|
+
*/
|
|
87
|
+
export function hasPrompt(name) {
|
|
88
|
+
return prompts.some((p) => p.name === name);
|
|
89
|
+
}
|
|
90
|
+
/** Singleton registry object — convenience wrapper over the named exports. */
|
|
91
|
+
export const promptRegistry = {
|
|
92
|
+
register: createAndRegisterPrompt,
|
|
93
|
+
listDefinitions: getPromptDefinitions,
|
|
94
|
+
get: renderPrompt,
|
|
95
|
+
get count() {
|
|
96
|
+
return getPromptCount();
|
|
97
|
+
},
|
|
98
|
+
has: hasPrompt,
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=prompt-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-registry.js","sourceRoot":"","sources":["../../src/core/prompt-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAE7C,gDAAgD;AAChD,MAAM,OAAO,GAAqB,EAAE,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAsB;IAC5D,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,YAAY,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,IAAI,sCAAsC,CAAC,CAAC;IAClF,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,YAAY,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAChC,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;Q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CAAC,MAAM,cAAc,GAAG;IAC5B,QAAQ,EAAE,uBAAuB;IACjC,eAAe,EAAE,oBAAoB;IACrC,GAAG,EAAE,YAAY;IACjB,IAAI,KAAK;QACP,OAAO,cAAc,EAAE,CAAC;IAC1B,CAAC;IACD,GAAG,EAAE,SAAS;CACf,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource Registry - Simplified with RFC 6570 Templates
|
|
3
|
+
*
|
|
4
|
+
* Auto-registration pattern with:
|
|
5
|
+
* - Direct array access for static resources
|
|
6
|
+
* - RFC 6570 URI template support for dynamic resources
|
|
7
|
+
*/
|
|
8
|
+
import type { MCPResource, ResourceProvider } from "./types.js";
|
|
9
|
+
import { TemplateRegistry } from "./resource-uri-templates.js";
|
|
10
|
+
type RegistryContentBlock = {
|
|
11
|
+
uri: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
mimeType?: string;
|
|
15
|
+
text?: string;
|
|
16
|
+
blob?: string;
|
|
17
|
+
annotations?: MCPResource["annotations"];
|
|
18
|
+
size?: number;
|
|
19
|
+
schema?: MCPResource["schema"];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Create and register a resource provider
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* const resource = createAndRegisterResource({ uri, name, read: async () => ({ text }) });
|
|
26
|
+
*
|
|
27
|
+
* Supports both static URIs and RFC 6570 URI templates:
|
|
28
|
+
* - Static: "cache://users/123"
|
|
29
|
+
* - Template: "cache://users/{id}"
|
|
30
|
+
*
|
|
31
|
+
* This function is called during resource module imports (auto-registration pattern)
|
|
32
|
+
*/
|
|
33
|
+
export declare function createAndRegisterResource(resource: ResourceProvider): ResourceProvider;
|
|
34
|
+
/**
|
|
35
|
+
* Unregister a resource by URI (used when TTL expires)
|
|
36
|
+
*/
|
|
37
|
+
export declare function unregisterResource(uri: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get all resource definitions (for MCP ListResources response)
|
|
40
|
+
*/
|
|
41
|
+
export declare function getResourceDefinitions(): MCPResource[];
|
|
42
|
+
/**
|
|
43
|
+
* Get a resource by URI
|
|
44
|
+
*/
|
|
45
|
+
export declare function getResource(uri: string): ResourceProvider | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Read a resource (resources/read)
|
|
48
|
+
*/
|
|
49
|
+
export declare function readResource(uri: string): Promise<{
|
|
50
|
+
contents: RegistryContentBlock[];
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Get count of registered resources
|
|
54
|
+
*/
|
|
55
|
+
export declare function getResourceCount(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Check if a resource exists
|
|
58
|
+
*/
|
|
59
|
+
export declare function hasResource(uri: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get all registered RFC 6570 URI template patterns
|
|
62
|
+
*/
|
|
63
|
+
export declare function getTemplatePatterns(): string[];
|
|
64
|
+
/**
|
|
65
|
+
* Get template registry (for advanced template operations)
|
|
66
|
+
*/
|
|
67
|
+
export declare function getTemplateRegistry(): TemplateRegistry;
|
|
68
|
+
export declare const resourceRegistry: {
|
|
69
|
+
register: typeof createAndRegisterResource;
|
|
70
|
+
unregister: typeof unregisterResource;
|
|
71
|
+
listDefinitions: typeof getResourceDefinitions;
|
|
72
|
+
read: typeof readResource;
|
|
73
|
+
readonly count: number;
|
|
74
|
+
has: typeof hasResource;
|
|
75
|
+
getTemplates: typeof getTemplatePatterns;
|
|
76
|
+
getTemplateRegistry: typeof getTemplateRegistry;
|
|
77
|
+
};
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=resource-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-registry.d.ts","sourceRoot":"","sources":["../../src/core/resource-registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAC,WAAW,EAAmB,gBAAgB,EAAC,MAAM,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