@malek0512/loopback4-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 +124 -0
- package/dist/component.d.ts +8 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/component.js +67 -0
- package/dist/component.js.map +1 -0
- package/dist/controllers/index.d.ts +2 -0
- package/dist/controllers/index.d.ts.map +1 -0
- package/dist/controllers/index.js +18 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/mcp.controller.d.ts +16 -0
- package/dist/controllers/mcp.controller.d.ts.map +1 -0
- package/dist/controllers/mcp.controller.js +66 -0
- package/dist/controllers/mcp.controller.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +18 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/mcp-tool.decorator.d.ts +21 -0
- package/dist/decorators/mcp-tool.decorator.d.ts.map +1 -0
- package/dist/decorators/mcp-tool.decorator.js +30 -0
- package/dist/decorators/mcp-tool.decorator.js.map +1 -0
- package/dist/execution/context-manager.d.ts +14 -0
- package/dist/execution/context-manager.d.ts.map +1 -0
- package/dist/execution/context-manager.js +41 -0
- package/dist/execution/context-manager.js.map +1 -0
- package/dist/execution/index.d.ts +4 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +20 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/result-formatter.d.ts +16 -0
- package/dist/execution/result-formatter.d.ts.map +1 -0
- package/dist/execution/result-formatter.js +102 -0
- package/dist/execution/result-formatter.js.map +1 -0
- package/dist/execution/tool-executor.d.ts +12 -0
- package/dist/execution/tool-executor.d.ts.map +1 -0
- package/dist/execution/tool-executor.js +72 -0
- package/dist/execution/tool-executor.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/observers/index.d.ts +2 -0
- package/dist/observers/index.d.ts.map +1 -0
- package/dist/observers/index.js +18 -0
- package/dist/observers/index.js.map +1 -0
- package/dist/observers/mcp-boot.observer.d.ts +9 -0
- package/dist/observers/mcp-boot.observer.d.ts.map +1 -0
- package/dist/observers/mcp-boot.observer.js +36 -0
- package/dist/observers/mcp-boot.observer.js.map +1 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +20 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/json-rpc.handler.d.ts +10 -0
- package/dist/protocol/json-rpc.handler.d.ts.map +1 -0
- package/dist/protocol/json-rpc.handler.js +63 -0
- package/dist/protocol/json-rpc.handler.js.map +1 -0
- package/dist/protocol/message-router.d.ts +18 -0
- package/dist/protocol/message-router.d.ts.map +1 -0
- package/dist/protocol/message-router.js +106 -0
- package/dist/protocol/message-router.js.map +1 -0
- package/dist/protocol/types.d.ts +227 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +56 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/registry/index.d.ts +4 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +20 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/metadata-scanner.d.ts +13 -0
- package/dist/registry/metadata-scanner.d.ts.map +1 -0
- package/dist/registry/metadata-scanner.js +101 -0
- package/dist/registry/metadata-scanner.js.map +1 -0
- package/dist/registry/schema-generator.d.ts +19 -0
- package/dist/registry/schema-generator.d.ts.map +1 -0
- package/dist/registry/schema-generator.js +90 -0
- package/dist/registry/schema-generator.js.map +1 -0
- package/dist/registry/tool-registry.d.ts +23 -0
- package/dist/registry/tool-registry.d.ts.map +1 -0
- package/dist/registry/tool-registry.js +58 -0
- package/dist/registry/tool-registry.js.map +1 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +18 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/sse.transport.d.ts +9 -0
- package/dist/transport/sse.transport.d.ts.map +1 -0
- package/dist/transport/sse.transport.js +67 -0
- package/dist/transport/sse.transport.js.map +1 -0
- package/package.json +26 -0
- package/src/component.ts +58 -0
- package/src/controllers/index.ts +1 -0
- package/src/controllers/mcp.controller.ts +42 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/mcp-tool.decorator.ts +57 -0
- package/src/execution/context-manager.ts +44 -0
- package/src/execution/index.ts +3 -0
- package/src/execution/result-formatter.ts +104 -0
- package/src/execution/tool-executor.ts +61 -0
- package/src/index.ts +5 -0
- package/src/observers/index.ts +1 -0
- package/src/observers/mcp-boot.observer.ts +19 -0
- package/src/protocol/index.ts +3 -0
- package/src/protocol/json-rpc.handler.ts +77 -0
- package/src/protocol/message-router.ts +125 -0
- package/src/protocol/types.ts +309 -0
- package/src/registry/index.ts +3 -0
- package/src/registry/metadata-scanner.ts +105 -0
- package/src/registry/schema-generator.ts +82 -0
- package/src/registry/tool-registry.ts +57 -0
- package/src/transport/index.ts +1 -0
- package/src/transport/sse.transport.ts +56 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
export interface JsonRpcRequest {
|
|
2
|
+
jsonrpc: '2.0';
|
|
3
|
+
id?: string | number;
|
|
4
|
+
method: string;
|
|
5
|
+
params?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface JsonRpcResponse {
|
|
8
|
+
jsonrpc: '2.0';
|
|
9
|
+
id: string | number;
|
|
10
|
+
result?: unknown;
|
|
11
|
+
error?: JsonRpcError;
|
|
12
|
+
}
|
|
13
|
+
export interface JsonRpcError {
|
|
14
|
+
code: number;
|
|
15
|
+
message: string;
|
|
16
|
+
data?: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface JsonRpcNotification {
|
|
19
|
+
jsonrpc: '2.0';
|
|
20
|
+
method: string;
|
|
21
|
+
params?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export declare enum McpMethod {
|
|
24
|
+
INITIALIZE = "initialize",
|
|
25
|
+
INITIALIZED = "initialized",
|
|
26
|
+
TOOLS_LIST = "tools/list",
|
|
27
|
+
TOOLS_CALL = "tools/call",
|
|
28
|
+
RESOURCES_LIST = "resources/list",
|
|
29
|
+
RESOURCES_READ = "resources/read",
|
|
30
|
+
RESOURCES_SUBSCRIBE = "resources/subscribe",
|
|
31
|
+
RESOURCES_UNSUBSCRIBE = "resources/unsubscribe",
|
|
32
|
+
PROMPTS_LIST = "prompts/list",
|
|
33
|
+
PROMPTS_GET = "prompts/get",
|
|
34
|
+
LOGGING_SET_LEVEL = "logging/setLevel",
|
|
35
|
+
NOTIFICATION_CANCELLED = "notifications/cancelled",
|
|
36
|
+
NOTIFICATION_PROGRESS = "notifications/progress",
|
|
37
|
+
NOTIFICATION_MESSAGE = "notifications/message",
|
|
38
|
+
NOTIFICATION_RESOURCES_UPDATED = "notifications/resources/updated",
|
|
39
|
+
NOTIFICATION_RESOURCES_LIST_CHANGED = "notifications/resources/list_changed",
|
|
40
|
+
NOTIFICATION_TOOLS_LIST_CHANGED = "notifications/tools/list_changed",
|
|
41
|
+
NOTIFICATION_PROMPTS_LIST_CHANGED = "notifications/prompts/list_changed"
|
|
42
|
+
}
|
|
43
|
+
export interface InitializeRequest extends JsonRpcRequest {
|
|
44
|
+
method: McpMethod.INITIALIZE;
|
|
45
|
+
params: {
|
|
46
|
+
protocolVersion: string;
|
|
47
|
+
capabilities: ClientCapabilities;
|
|
48
|
+
clientInfo: Implementation;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface InitializeResult {
|
|
52
|
+
protocolVersion: string;
|
|
53
|
+
capabilities: ServerCapabilities;
|
|
54
|
+
serverInfo: Implementation;
|
|
55
|
+
}
|
|
56
|
+
export interface Implementation {
|
|
57
|
+
name: string;
|
|
58
|
+
version: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ClientCapabilities {
|
|
61
|
+
experimental?: Record<string, unknown>;
|
|
62
|
+
sampling?: Record<string, unknown>;
|
|
63
|
+
roots?: {
|
|
64
|
+
listChanged?: boolean;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export interface ServerCapabilities {
|
|
68
|
+
experimental?: Record<string, unknown>;
|
|
69
|
+
logging?: Record<string, unknown>;
|
|
70
|
+
prompts?: {
|
|
71
|
+
listChanged?: boolean;
|
|
72
|
+
};
|
|
73
|
+
resources?: {
|
|
74
|
+
subscribe?: boolean;
|
|
75
|
+
listChanged?: boolean;
|
|
76
|
+
};
|
|
77
|
+
tools?: {
|
|
78
|
+
listChanged?: boolean;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export interface Tool {
|
|
82
|
+
name: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
inputSchema: {
|
|
85
|
+
type: 'object';
|
|
86
|
+
properties?: Record<string, JsonSchema>;
|
|
87
|
+
required?: string[];
|
|
88
|
+
additionalProperties?: boolean;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export interface ToolsListRequest extends JsonRpcRequest {
|
|
92
|
+
method: McpMethod.TOOLS_LIST;
|
|
93
|
+
params?: {
|
|
94
|
+
cursor?: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface ToolsListResult {
|
|
98
|
+
tools: Tool[];
|
|
99
|
+
nextCursor?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface ToolCallRequest extends JsonRpcRequest {
|
|
102
|
+
method: McpMethod.TOOLS_CALL;
|
|
103
|
+
params: {
|
|
104
|
+
name: string;
|
|
105
|
+
arguments?: Record<string, unknown>;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export interface ToolCallResult {
|
|
109
|
+
content: Content[];
|
|
110
|
+
isError?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export type Content = TextContent | ImageContent | EmbeddedResource;
|
|
113
|
+
export interface TextContent {
|
|
114
|
+
type: 'text';
|
|
115
|
+
text: string;
|
|
116
|
+
}
|
|
117
|
+
export interface ImageContent {
|
|
118
|
+
type: 'image';
|
|
119
|
+
data: string;
|
|
120
|
+
mimeType: string;
|
|
121
|
+
}
|
|
122
|
+
export interface EmbeddedResource {
|
|
123
|
+
type: 'resource';
|
|
124
|
+
resource: ResourceContents;
|
|
125
|
+
}
|
|
126
|
+
export interface Resource {
|
|
127
|
+
uri: string;
|
|
128
|
+
name: string;
|
|
129
|
+
description?: string;
|
|
130
|
+
mimeType?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface ResourcesListRequest extends JsonRpcRequest {
|
|
133
|
+
method: McpMethod.RESOURCES_LIST;
|
|
134
|
+
params?: {
|
|
135
|
+
cursor?: string;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
export interface ResourcesListResult {
|
|
139
|
+
resources: Resource[];
|
|
140
|
+
nextCursor?: string;
|
|
141
|
+
}
|
|
142
|
+
export interface ResourceReadRequest extends JsonRpcRequest {
|
|
143
|
+
method: McpMethod.RESOURCES_READ;
|
|
144
|
+
params: {
|
|
145
|
+
uri: string;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export interface ResourceContents {
|
|
149
|
+
uri: string;
|
|
150
|
+
mimeType?: string;
|
|
151
|
+
text?: string;
|
|
152
|
+
blob?: string;
|
|
153
|
+
}
|
|
154
|
+
export interface ResourceReadResult {
|
|
155
|
+
contents: ResourceContents[];
|
|
156
|
+
}
|
|
157
|
+
export interface Prompt {
|
|
158
|
+
name: string;
|
|
159
|
+
description?: string;
|
|
160
|
+
arguments?: PromptArgument[];
|
|
161
|
+
}
|
|
162
|
+
export interface PromptArgument {
|
|
163
|
+
name: string;
|
|
164
|
+
description?: string;
|
|
165
|
+
required?: boolean;
|
|
166
|
+
}
|
|
167
|
+
export interface PromptsListRequest extends JsonRpcRequest {
|
|
168
|
+
method: McpMethod.PROMPTS_LIST;
|
|
169
|
+
params?: {
|
|
170
|
+
cursor?: string;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export interface PromptsListResult {
|
|
174
|
+
prompts: Prompt[];
|
|
175
|
+
nextCursor?: string;
|
|
176
|
+
}
|
|
177
|
+
export interface PromptGetRequest extends JsonRpcRequest {
|
|
178
|
+
method: McpMethod.PROMPTS_GET;
|
|
179
|
+
params: {
|
|
180
|
+
name: string;
|
|
181
|
+
arguments?: Record<string, string>;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export interface PromptMessage {
|
|
185
|
+
role: 'user' | 'assistant';
|
|
186
|
+
content: Content;
|
|
187
|
+
}
|
|
188
|
+
export interface PromptGetResult {
|
|
189
|
+
description?: string;
|
|
190
|
+
messages: PromptMessage[];
|
|
191
|
+
}
|
|
192
|
+
export interface JsonSchema {
|
|
193
|
+
type?: string | string[];
|
|
194
|
+
properties?: Record<string, JsonSchema>;
|
|
195
|
+
items?: JsonSchema | JsonSchema[];
|
|
196
|
+
required?: string[];
|
|
197
|
+
enum?: unknown[];
|
|
198
|
+
const?: unknown;
|
|
199
|
+
description?: string;
|
|
200
|
+
default?: unknown;
|
|
201
|
+
examples?: unknown[];
|
|
202
|
+
format?: string;
|
|
203
|
+
pattern?: string;
|
|
204
|
+
minimum?: number;
|
|
205
|
+
maximum?: number;
|
|
206
|
+
minLength?: number;
|
|
207
|
+
maxLength?: number;
|
|
208
|
+
minItems?: number;
|
|
209
|
+
maxItems?: number;
|
|
210
|
+
uniqueItems?: boolean;
|
|
211
|
+
additionalProperties?: boolean | JsonSchema;
|
|
212
|
+
[key: string]: unknown;
|
|
213
|
+
}
|
|
214
|
+
export declare enum McpErrorCode {
|
|
215
|
+
PARSE_ERROR = -32700,
|
|
216
|
+
INVALID_REQUEST = -32600,
|
|
217
|
+
METHOD_NOT_FOUND = -32601,
|
|
218
|
+
INVALID_PARAMS = -32602,
|
|
219
|
+
INTERNAL_ERROR = -32603,
|
|
220
|
+
TOOL_NOT_FOUND = -32001,
|
|
221
|
+
TOOL_EXECUTION_ERROR = -32002,
|
|
222
|
+
RESOURCE_NOT_FOUND = -32003,
|
|
223
|
+
RESOURCE_ACCESS_DENIED = -32004,
|
|
224
|
+
PROMPT_NOT_FOUND = -32005,
|
|
225
|
+
INVALID_TOOL_ARGUMENTS = -32006
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/protocol/types.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAMD,oBAAY,SAAS;IAEnB,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAG3B,UAAU,eAAe;IACzB,UAAU,eAAe;IAGzB,cAAc,mBAAmB;IACjC,cAAc,mBAAmB;IACjC,mBAAmB,wBAAwB;IAC3C,qBAAqB,0BAA0B;IAG/C,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAG3B,iBAAiB,qBAAqB;IAGtC,sBAAsB,4BAA4B;IAClD,qBAAqB,2BAA2B;IA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B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAMD,oBAAY,YAAY;IAEtB,WAAW,SAAS;IACpB,eAAe,SAAS;IACxB,gBAAgB,SAAS;IACzB,cAAc,SAAS;IACvB,cAAc,SAAS;IAGvB,cAAc,SAAS;IACvB,oBAAoB,SAAS;IAC7B,kBAAkB,SAAS;IAC3B,sBAAsB,SAAS;IAC/B,gBAAgB,SAAS;IACzB,sBAAsB,SAAS;CAChC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// JSON-RPC 2.0 Base Types
|
|
4
|
+
// ============================================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.McpErrorCode = exports.McpMethod = void 0;
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// MCP Protocol Messages
|
|
9
|
+
// ============================================================================
|
|
10
|
+
var McpMethod;
|
|
11
|
+
(function (McpMethod) {
|
|
12
|
+
// Initialization
|
|
13
|
+
McpMethod["INITIALIZE"] = "initialize";
|
|
14
|
+
McpMethod["INITIALIZED"] = "initialized";
|
|
15
|
+
// Tools
|
|
16
|
+
McpMethod["TOOLS_LIST"] = "tools/list";
|
|
17
|
+
McpMethod["TOOLS_CALL"] = "tools/call";
|
|
18
|
+
// Resources
|
|
19
|
+
McpMethod["RESOURCES_LIST"] = "resources/list";
|
|
20
|
+
McpMethod["RESOURCES_READ"] = "resources/read";
|
|
21
|
+
McpMethod["RESOURCES_SUBSCRIBE"] = "resources/subscribe";
|
|
22
|
+
McpMethod["RESOURCES_UNSUBSCRIBE"] = "resources/unsubscribe";
|
|
23
|
+
// Prompts
|
|
24
|
+
McpMethod["PROMPTS_LIST"] = "prompts/list";
|
|
25
|
+
McpMethod["PROMPTS_GET"] = "prompts/get";
|
|
26
|
+
// Logging
|
|
27
|
+
McpMethod["LOGGING_SET_LEVEL"] = "logging/setLevel";
|
|
28
|
+
// Notifications
|
|
29
|
+
McpMethod["NOTIFICATION_CANCELLED"] = "notifications/cancelled";
|
|
30
|
+
McpMethod["NOTIFICATION_PROGRESS"] = "notifications/progress";
|
|
31
|
+
McpMethod["NOTIFICATION_MESSAGE"] = "notifications/message";
|
|
32
|
+
McpMethod["NOTIFICATION_RESOURCES_UPDATED"] = "notifications/resources/updated";
|
|
33
|
+
McpMethod["NOTIFICATION_RESOURCES_LIST_CHANGED"] = "notifications/resources/list_changed";
|
|
34
|
+
McpMethod["NOTIFICATION_TOOLS_LIST_CHANGED"] = "notifications/tools/list_changed";
|
|
35
|
+
McpMethod["NOTIFICATION_PROMPTS_LIST_CHANGED"] = "notifications/prompts/list_changed";
|
|
36
|
+
})(McpMethod || (exports.McpMethod = McpMethod = {}));
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// Error Codes
|
|
39
|
+
// ============================================================================
|
|
40
|
+
var McpErrorCode;
|
|
41
|
+
(function (McpErrorCode) {
|
|
42
|
+
// Standard JSON-RPC errors
|
|
43
|
+
McpErrorCode[McpErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
44
|
+
McpErrorCode[McpErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
45
|
+
McpErrorCode[McpErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
46
|
+
McpErrorCode[McpErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
47
|
+
McpErrorCode[McpErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
48
|
+
// MCP-specific errors
|
|
49
|
+
McpErrorCode[McpErrorCode["TOOL_NOT_FOUND"] = -32001] = "TOOL_NOT_FOUND";
|
|
50
|
+
McpErrorCode[McpErrorCode["TOOL_EXECUTION_ERROR"] = -32002] = "TOOL_EXECUTION_ERROR";
|
|
51
|
+
McpErrorCode[McpErrorCode["RESOURCE_NOT_FOUND"] = -32003] = "RESOURCE_NOT_FOUND";
|
|
52
|
+
McpErrorCode[McpErrorCode["RESOURCE_ACCESS_DENIED"] = -32004] = "RESOURCE_ACCESS_DENIED";
|
|
53
|
+
McpErrorCode[McpErrorCode["PROMPT_NOT_FOUND"] = -32005] = "PROMPT_NOT_FOUND";
|
|
54
|
+
McpErrorCode[McpErrorCode["INVALID_TOOL_ARGUMENTS"] = -32006] = "INVALID_TOOL_ARGUMENTS";
|
|
55
|
+
})(McpErrorCode || (exports.McpErrorCode = McpErrorCode = {}));
|
|
56
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/protocol/types.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;;;AA4B/E,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E,IAAY,SA8BX;AA9BD,WAAY,SAAS;IACnB,iBAAiB;IACjB,sCAAyB,CAAA;IACzB,wCAA2B,CAAA;IAE3B,QAAQ;IACR,sCAAyB,CAAA;IACzB,sCAAyB,CAAA;IAEzB,YAAY;IACZ,8CAAiC,CAAA;IACjC,8CAAiC,CAAA;IACjC,wDAA2C,CAAA;IAC3C,4DAA+C,CAAA;IAE/C,UAAU;IACV,0CAA6B,CAAA;IAC7B,wCAA2B,CAAA;IAE3B,UAAU;IACV,mDAAsC,CAAA;IAEtC,gBAAgB;IAChB,+DAAkD,CAAA;IAClD,6DAAgD,CAAA;IAChD,2DAA8C,CAAA;IAC9C,+EAAkE,CAAA;IAClE,yFAA4E,CAAA;IAC5E,iFAAoE,CAAA;IACpE,qFAAwE,CAAA;AAC1E,CAAC,EA9BW,SAAS,yBAAT,SAAS,QA8BpB;AAiOD,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E,IAAY,YAeX;AAfD,WAAY,YAAY;IACtB,2BAA2B;IAC3B,kEAAoB,CAAA;IACpB,0EAAwB,CAAA;IACxB,4EAAyB,CAAA;IACzB,wEAAuB,CAAA;IACvB,wEAAuB,CAAA;IAEvB,sBAAsB;IACtB,wEAAuB,CAAA;IACvB,oFAA6B,CAAA;IAC7B,gFAA2B,CAAA;IAC3B,wFAA+B,CAAA;IAC/B,4EAAyB,CAAA;IACzB,wFAA+B,CAAA;AACjC,CAAC,EAfW,YAAY,4BAAZ,YAAY,QAevB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./tool-registry"), exports);
|
|
18
|
+
__exportStar(require("./metadata-scanner"), exports);
|
|
19
|
+
__exportStar(require("./schema-generator"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,qDAAmC;AACnC,qDAAmC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Application } from '@loopback/core';
|
|
2
|
+
import { ToolRegistry } from './tool-registry';
|
|
3
|
+
import { SchemaGenerator } from './schema-generator';
|
|
4
|
+
export declare class MetadataScanner {
|
|
5
|
+
private toolRegistry;
|
|
6
|
+
private schemaGenerator;
|
|
7
|
+
private app;
|
|
8
|
+
constructor(toolRegistry: ToolRegistry, schemaGenerator: SchemaGenerator, app: Application);
|
|
9
|
+
scan(): Promise<void>;
|
|
10
|
+
private scanControllerClass;
|
|
11
|
+
private registerTool;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=metadata-scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-scanner.d.ts","sourceRoot":"","sources":["../../src/registry/metadata-scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,WAAW,EAAC,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAC,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAGnD,qBACa,eAAe;IAGxB,OAAO,CAAC,YAAY;IAEpB,OAAO,CAAC,eAAe;IAEvB,OAAO,CAAC,GAAG;gBAJH,YAAY,EAAE,YAAY,EAE1B,eAAe,EAAE,eAAe,EAEhC,GAAG,EAAE,WAAW;IAGpB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAUb,mBAAmB;YAsBnB,YAAY;CAuD3B"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MetadataScanner = void 0;
|
|
16
|
+
const core_1 = require("@loopback/core");
|
|
17
|
+
const tool_registry_1 = require("./tool-registry");
|
|
18
|
+
const decorators_1 = require("../decorators");
|
|
19
|
+
const schema_generator_1 = require("./schema-generator");
|
|
20
|
+
const core_2 = require("@loopback/core");
|
|
21
|
+
let MetadataScanner = class MetadataScanner {
|
|
22
|
+
constructor(toolRegistry, schemaGenerator, app) {
|
|
23
|
+
this.toolRegistry = toolRegistry;
|
|
24
|
+
this.schemaGenerator = schemaGenerator;
|
|
25
|
+
this.app = app;
|
|
26
|
+
}
|
|
27
|
+
async scan() {
|
|
28
|
+
const controllerBindings = this.app.findByTag('controller');
|
|
29
|
+
for (const binding of controllerBindings) {
|
|
30
|
+
const controllerClass = binding.valueConstructor;
|
|
31
|
+
if (controllerClass) {
|
|
32
|
+
await this.scanControllerClass(controllerClass);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async scanControllerClass(controllerClass) {
|
|
37
|
+
try {
|
|
38
|
+
const proto = controllerClass.prototype;
|
|
39
|
+
const methodNames = Object.getOwnPropertyNames(proto).filter(name => typeof proto[name] === 'function' && name !== 'constructor');
|
|
40
|
+
for (const methodName of methodNames) {
|
|
41
|
+
const metadata = core_2.MetadataInspector.getMethodMetadata(decorators_1.MCP_TOOL_METADATA_KEY, proto, methodName);
|
|
42
|
+
if (metadata) {
|
|
43
|
+
await this.registerTool(controllerClass, methodName, metadata);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.warn(`[MCP] Skipping controller during scan:`, error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async registerTool(controllerClass, methodName, metadata) {
|
|
52
|
+
// Schema: use LoopBack's own spec generation (resolves $ref, always correct)
|
|
53
|
+
const inputSchema = metadata.inputSchema ?? this.schemaGenerator.generateForMethod(controllerClass, methodName);
|
|
54
|
+
// Handler arg mapping: read raw LoopBack parameter metadata set at class-definition time
|
|
55
|
+
const proto = controllerClass.prototype;
|
|
56
|
+
const allParamsMeta = Reflect.getMetadata('loopback:openapi-v3:parameters', proto) ?? {};
|
|
57
|
+
const allReqBodyMeta = Reflect.getMetadata('loopback:openapi-v3:request-body', proto) ?? {};
|
|
58
|
+
const methodParams = allParamsMeta[methodName] ?? [];
|
|
59
|
+
const methodReqBodies = allReqBodyMeta[methodName] ?? [];
|
|
60
|
+
const maxArgs = Math.max(methodParams.length, methodReqBodies.length);
|
|
61
|
+
const descriptor = {
|
|
62
|
+
name: metadata.name,
|
|
63
|
+
description: metadata.description,
|
|
64
|
+
inputSchema,
|
|
65
|
+
controller: proto,
|
|
66
|
+
methodName,
|
|
67
|
+
handler: async (args) => {
|
|
68
|
+
const controller = await this.app.get(`controllers.${controllerClass.name}`);
|
|
69
|
+
if (maxArgs === 0) {
|
|
70
|
+
return controller[methodName](args);
|
|
71
|
+
}
|
|
72
|
+
const positionalArgs = [];
|
|
73
|
+
const usedKeys = new Set();
|
|
74
|
+
for (let i = 0; i < maxArgs; i++) {
|
|
75
|
+
const param = methodParams[i];
|
|
76
|
+
const reqBody = methodReqBodies[i];
|
|
77
|
+
if (param) {
|
|
78
|
+
positionalArgs[i] = args[param.name];
|
|
79
|
+
usedKeys.add(param.name);
|
|
80
|
+
}
|
|
81
|
+
else if (reqBody) {
|
|
82
|
+
positionalArgs[i] = Object.fromEntries(Object.entries(args).filter(([k]) => !usedKeys.has(k)));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return controller[methodName](...positionalArgs);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
this.toolRegistry.register(descriptor);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.MetadataScanner = MetadataScanner;
|
|
92
|
+
exports.MetadataScanner = MetadataScanner = __decorate([
|
|
93
|
+
(0, core_1.bind)({ scope: core_1.BindingScope.SINGLETON }),
|
|
94
|
+
__param(0, (0, core_1.inject)('mcp.toolRegistry')),
|
|
95
|
+
__param(1, (0, core_1.inject)('mcp.schemaGenerator')),
|
|
96
|
+
__param(2, core_1.inject.context()),
|
|
97
|
+
__metadata("design:paramtypes", [tool_registry_1.ToolRegistry,
|
|
98
|
+
schema_generator_1.SchemaGenerator,
|
|
99
|
+
core_1.Application])
|
|
100
|
+
], MetadataScanner);
|
|
101
|
+
//# sourceMappingURL=metadata-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-scanner.js","sourceRoot":"","sources":["../../src/registry/metadata-scanner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAAuE;AACvE,mDAA6D;AAC7D,8CAAqE;AACrE,yDAAmD;AACnD,yCAAiD;AAG1C,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YAEU,YAA0B,EAE1B,eAAgC,EAEhC,GAAgB;QAJhB,iBAAY,GAAZ,YAAY,CAAc;QAE1B,oBAAe,GAAf,eAAe,CAAiB;QAEhC,QAAG,GAAH,GAAG,CAAa;IACvB,CA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BACV,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;wBACrC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAC3B,CAAC;yBAAM,IAAI,OAAO,EAAE,CAAC;wBACnB,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,CACpC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CACvD,CAAC;oBACJ,CAAC;gBACH,CAAC;gBAED,OAAQ,UAAkB,CAAC,UAAU,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC;YAC5D,CAAC;SACF,CAAC;QAEF,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;CACF,CAAA;AAjGY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,WAAI,EAAC,EAAC,KAAK,EAAE,mBAAY,CAAC,SAAS,EAAC,CAAC;IAGjC,WAAA,IAAA,aAAM,EAAC,kBAAkB,CAAC,CAAA;IAE1B,WAAA,IAAA,aAAM,EAAC,qBAAqB,CAAC,CAAA;IAE7B,WAAA,aAAM,CAAC,OAAO,EAAE,CAAA;qCAHK,4BAAY;QAET,kCAAe;QAE3B,kBAAW;GAPf,eAAe,CAiG3B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JsonSchema } from '../protocol/types';
|
|
2
|
+
export declare class SchemaGenerator {
|
|
3
|
+
/**
|
|
4
|
+
* Build the MCP inputSchema for a controller method using LoopBack's
|
|
5
|
+
* own getControllerSpec(), so $ref resolution and parameter ordering
|
|
6
|
+
* are always correct regardless of decorator evaluation timing.
|
|
7
|
+
*
|
|
8
|
+
* Path params become required top-level properties.
|
|
9
|
+
* Request body properties are spread into the top-level object.
|
|
10
|
+
* Optional query params (filter, where…) are omitted — MCP tools
|
|
11
|
+
* accept them as part of the body object when passed.
|
|
12
|
+
*/
|
|
13
|
+
generateForMethod(controllerClass: Function, methodName: string): JsonSchema;
|
|
14
|
+
/** Resolve a $ref schema from components.schemas, or return it as-is. */
|
|
15
|
+
private resolveRef;
|
|
16
|
+
/** Find the OpenAPI operation matching a controller method by x-operation-name. */
|
|
17
|
+
private findOperation;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=schema-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-generator.d.ts","sourceRoot":"","sources":["../../src/registry/schema-generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAE7C,qBACa,eAAe;IAC1B;;;;;;;;;OASG;IACH,iBAAiB,CAAC,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU;IA8C5E,yEAAyE;IACzE,OAAO,CAAC,UAAU;IAOlB,mFAAmF;IACnF,OAAO,CAAC,aAAa;CAUtB"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SchemaGenerator = void 0;
|
|
10
|
+
const core_1 = require("@loopback/core");
|
|
11
|
+
const openapi_v3_1 = require("@loopback/openapi-v3");
|
|
12
|
+
let SchemaGenerator = class SchemaGenerator {
|
|
13
|
+
/**
|
|
14
|
+
* Build the MCP inputSchema for a controller method using LoopBack's
|
|
15
|
+
* own getControllerSpec(), so $ref resolution and parameter ordering
|
|
16
|
+
* are always correct regardless of decorator evaluation timing.
|
|
17
|
+
*
|
|
18
|
+
* Path params become required top-level properties.
|
|
19
|
+
* Request body properties are spread into the top-level object.
|
|
20
|
+
* Optional query params (filter, where…) are omitted — MCP tools
|
|
21
|
+
* accept them as part of the body object when passed.
|
|
22
|
+
*/
|
|
23
|
+
generateForMethod(controllerClass, methodName) {
|
|
24
|
+
const spec = (0, openapi_v3_1.getControllerSpec)(controllerClass);
|
|
25
|
+
const components = spec.components?.schemas ?? {};
|
|
26
|
+
const operation = this.findOperation(spec, methodName);
|
|
27
|
+
if (!operation) {
|
|
28
|
+
return { type: 'object', properties: {}, additionalProperties: false };
|
|
29
|
+
}
|
|
30
|
+
const properties = {};
|
|
31
|
+
const required = [];
|
|
32
|
+
const usedKeys = new Set();
|
|
33
|
+
// Path parameters (required, strongly typed)
|
|
34
|
+
for (const param of (operation.parameters ?? [])) {
|
|
35
|
+
if (param.in !== 'path')
|
|
36
|
+
continue;
|
|
37
|
+
const schema = this.resolveRef(param.schema ?? { type: 'string' }, components);
|
|
38
|
+
properties[param.name] = schema;
|
|
39
|
+
usedKeys.add(param.name);
|
|
40
|
+
required.push(param.name);
|
|
41
|
+
}
|
|
42
|
+
// Request body: spread its resolved properties into the top-level schema
|
|
43
|
+
const bodyContent = operation.requestBody?.content?.['application/json'];
|
|
44
|
+
if (bodyContent?.schema) {
|
|
45
|
+
const bodySchema = this.resolveRef(bodyContent.schema, components);
|
|
46
|
+
if (bodySchema.properties) {
|
|
47
|
+
for (const [key, val] of Object.entries(bodySchema.properties)) {
|
|
48
|
+
if (!usedKeys.has(key)) {
|
|
49
|
+
properties[key] = this.resolveRef(val, components);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const r of bodySchema.required ?? []) {
|
|
53
|
+
if (!required.includes(r))
|
|
54
|
+
required.push(r);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties,
|
|
61
|
+
required: required.length > 0 ? required : undefined,
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Resolve a $ref schema from components.schemas, or return it as-is. */
|
|
66
|
+
resolveRef(schema, components) {
|
|
67
|
+
if (!schema || typeof schema !== 'object')
|
|
68
|
+
return schema;
|
|
69
|
+
if (!schema['$ref'])
|
|
70
|
+
return schema;
|
|
71
|
+
const refName = schema['$ref'].split('/').pop();
|
|
72
|
+
return components[refName] ?? schema;
|
|
73
|
+
}
|
|
74
|
+
/** Find the OpenAPI operation matching a controller method by x-operation-name. */
|
|
75
|
+
findOperation(spec, methodName) {
|
|
76
|
+
for (const pathItem of Object.values(spec.paths ?? {})) {
|
|
77
|
+
for (const op of Object.values(pathItem)) {
|
|
78
|
+
if (op && op['x-operation-name'] === methodName) {
|
|
79
|
+
return op;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
exports.SchemaGenerator = SchemaGenerator;
|
|
87
|
+
exports.SchemaGenerator = SchemaGenerator = __decorate([
|
|
88
|
+
(0, core_1.bind)({ scope: core_1.BindingScope.SINGLETON })
|
|
89
|
+
], SchemaGenerator);
|
|
90
|
+
//# sourceMappingURL=schema-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-generator.js","sourceRoot":"","sources":["../../src/registry/schema-generator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yCAAkD;AAClD,qDAAuD;AAIhD,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B;;;;;;;;;OASG;IACH,iBAAiB,CAAC,eAAyB,EAAE,UAAk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,EAAE,CAAC,EAAE,CAAC;YACvD,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,MAAM,CAAC,QAAkB,CAAC,EAAE,CAAC;gBACnD,IAAI,EAAE,IAAK,EAAU,CAAC,kBAAkB,CAAC,KAAK,UAAU,EAAE,CAAC;oBACzD,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA5EY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,WAAI,EAAC,EAAC,KAAK,EAAE,mBAAY,CAAC,SAAS,EAAC,CAAC;GACzB,eAAe,CA4E3B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Tool, JsonSchema } from '../protocol/types';
|
|
2
|
+
import { SchemaGenerator } from './schema-generator';
|
|
3
|
+
export interface ToolDescriptor {
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
inputSchema: JsonSchema;
|
|
7
|
+
controller: Object;
|
|
8
|
+
methodName: string;
|
|
9
|
+
handler: Function;
|
|
10
|
+
}
|
|
11
|
+
export declare class ToolRegistry {
|
|
12
|
+
private schemaGenerator;
|
|
13
|
+
private tools;
|
|
14
|
+
constructor(schemaGenerator: SchemaGenerator);
|
|
15
|
+
register(descriptor: ToolDescriptor): void;
|
|
16
|
+
unregister(name: string): boolean;
|
|
17
|
+
get(name: string): ToolDescriptor | undefined;
|
|
18
|
+
list(): Tool[];
|
|
19
|
+
has(name: string): boolean;
|
|
20
|
+
clear(): void;
|
|
21
|
+
get size(): number;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=tool-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../src/registry/tool-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAE,UAAU,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,UAAU,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,QAAQ,CAAC;CACnB;AAED,qBACa,YAAY;IAKrB,OAAO,CAAC,eAAe;IAJzB,OAAO,CAAC,KAAK,CAAqC;gBAIxC,eAAe,EAAE,eAAe;IAG1C,QAAQ,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI;IAO1C,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI7C,IAAI,IAAI,IAAI,EAAE;IAQd,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|