@mcp-weave/nestjs 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/dist/index.d.mts +248 -0
- package/dist/index.d.ts +248 -0
- package/dist/index.js +343 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +318 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mcp-weave
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { ToolInputSchema, PromptArgument, McpParamMetadata, McpPromptMetadata, McpResourceMetadata, McpServerMetadata, McpToolMetadata } from '@mcp-weave/core';
|
|
2
|
+
export { METADATA_KEYS, McpParamMetadata, McpPromptMetadata, McpResourceMetadata, McpServerMetadata, McpToolMetadata, ScannedMetadata, extractMetadata } from '@mcp-weave/core';
|
|
3
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for @McpServer decorator
|
|
7
|
+
*/
|
|
8
|
+
interface McpServerOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Server name
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Server version (default: '1.0.0')
|
|
15
|
+
*/
|
|
16
|
+
version?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Server description
|
|
19
|
+
*/
|
|
20
|
+
description?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Marks a class as an MCP server
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* @McpServer({ name: 'my-service', version: '1.0.0' })
|
|
28
|
+
* export class MyController {
|
|
29
|
+
* // ...
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function McpServer(options: McpServerOptions): ClassDecorator;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Options for @McpTool decorator
|
|
37
|
+
*/
|
|
38
|
+
interface McpToolOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Tool name
|
|
41
|
+
*/
|
|
42
|
+
name: string;
|
|
43
|
+
/**
|
|
44
|
+
* Tool description
|
|
45
|
+
*/
|
|
46
|
+
description: string;
|
|
47
|
+
/**
|
|
48
|
+
* Input schema (JSON Schema)
|
|
49
|
+
*/
|
|
50
|
+
inputSchema?: ToolInputSchema;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Marks a method as an MCP tool
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* @McpTool({
|
|
58
|
+
* name: 'create_user',
|
|
59
|
+
* description: 'Creates a new user'
|
|
60
|
+
* })
|
|
61
|
+
* async createUser(@McpInput() input: CreateUserDto) {
|
|
62
|
+
* return { success: true };
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function McpTool(options: McpToolOptions): MethodDecorator;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Options for @McpResource decorator
|
|
70
|
+
*/
|
|
71
|
+
interface McpResourceOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Resource URI template (e.g., 'user://{userId}')
|
|
74
|
+
*/
|
|
75
|
+
uri: string;
|
|
76
|
+
/**
|
|
77
|
+
* Resource name
|
|
78
|
+
*/
|
|
79
|
+
name: string;
|
|
80
|
+
/**
|
|
81
|
+
* Resource description
|
|
82
|
+
*/
|
|
83
|
+
description?: string;
|
|
84
|
+
/**
|
|
85
|
+
* MIME type (default: 'application/json')
|
|
86
|
+
*/
|
|
87
|
+
mimeType?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Marks a method as an MCP resource
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* @McpResource({
|
|
95
|
+
* uri: 'user://{userId}',
|
|
96
|
+
* name: 'User Profile',
|
|
97
|
+
* mimeType: 'application/json'
|
|
98
|
+
* })
|
|
99
|
+
* async getUserProfile(@McpParam('userId') userId: string) {
|
|
100
|
+
* return { contents: [...] };
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function McpResource(options: McpResourceOptions): MethodDecorator;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Options for @McpPrompt decorator
|
|
108
|
+
*/
|
|
109
|
+
interface McpPromptOptions {
|
|
110
|
+
/**
|
|
111
|
+
* Prompt name
|
|
112
|
+
*/
|
|
113
|
+
name: string;
|
|
114
|
+
/**
|
|
115
|
+
* Prompt description
|
|
116
|
+
*/
|
|
117
|
+
description: string;
|
|
118
|
+
/**
|
|
119
|
+
* Prompt arguments
|
|
120
|
+
*/
|
|
121
|
+
arguments?: PromptArgument[];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Marks a method as an MCP prompt
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* @McpPrompt({
|
|
129
|
+
* name: 'welcome_email',
|
|
130
|
+
* description: 'Generate welcome email for new user'
|
|
131
|
+
* })
|
|
132
|
+
* async generateWelcomeEmail(
|
|
133
|
+
* @McpPromptArg('userName') userName: string
|
|
134
|
+
* ) {
|
|
135
|
+
* return { messages: [...] };
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare function McpPrompt(options: McpPromptOptions): MethodDecorator;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Injects the tool input
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* @McpTool({ name: 'create_user', description: 'Creates a user' })
|
|
147
|
+
* async createUser(@McpInput() input: CreateUserDto) {
|
|
148
|
+
* // input contains the tool arguments
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare function McpInput(): ParameterDecorator;
|
|
153
|
+
/**
|
|
154
|
+
* Injects a URI parameter from a resource
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* @McpResource({ uri: 'user://{userId}', name: 'User' })
|
|
159
|
+
* async getUser(@McpParam('userId') userId: string) {
|
|
160
|
+
* // userId is extracted from the URI
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function McpParam(name: string): ParameterDecorator;
|
|
165
|
+
/**
|
|
166
|
+
* Injects a prompt argument
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* @McpPrompt({ name: 'welcome', description: 'Welcome prompt' })
|
|
171
|
+
* async generateWelcome(@McpPromptArg('userName') userName: string) {
|
|
172
|
+
* // userName is the prompt argument
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function McpPromptArg(name: string): ParameterDecorator;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Check if a class has @McpServer decorator
|
|
180
|
+
*/
|
|
181
|
+
declare function isMcpServer(target: Function): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Get all MCP servers from an array of classes
|
|
184
|
+
*/
|
|
185
|
+
declare function getMcpServers(targets: Function[]): Function[];
|
|
186
|
+
/**
|
|
187
|
+
* Get server metadata from a class
|
|
188
|
+
*/
|
|
189
|
+
declare function getServerMetadata(target: Function): McpServerMetadata | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Get tools metadata from a class
|
|
192
|
+
*/
|
|
193
|
+
declare function getToolsMetadata(target: Function): McpToolMetadata[];
|
|
194
|
+
/**
|
|
195
|
+
* Get resources metadata from a class
|
|
196
|
+
*/
|
|
197
|
+
declare function getResourcesMetadata(target: Function): McpResourceMetadata[];
|
|
198
|
+
/**
|
|
199
|
+
* Get prompts metadata from a class
|
|
200
|
+
*/
|
|
201
|
+
declare function getPromptsMetadata(target: Function): McpPromptMetadata[];
|
|
202
|
+
/**
|
|
203
|
+
* Get params metadata from a class
|
|
204
|
+
*/
|
|
205
|
+
declare function getParamsMetadata(target: Function): McpParamMetadata[];
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Options for MCP runtime server
|
|
209
|
+
*/
|
|
210
|
+
interface McpRuntimeOptions {
|
|
211
|
+
/**
|
|
212
|
+
* Transport type
|
|
213
|
+
*/
|
|
214
|
+
transport?: 'stdio' | 'sse';
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Runtime MCP server that wraps a decorated class
|
|
218
|
+
*/
|
|
219
|
+
declare class McpRuntimeServer {
|
|
220
|
+
private server;
|
|
221
|
+
private instance;
|
|
222
|
+
private metadata;
|
|
223
|
+
constructor(target: Function, _options?: McpRuntimeOptions);
|
|
224
|
+
private setupHandlers;
|
|
225
|
+
private setupToolHandlers;
|
|
226
|
+
private setupResourceHandlers;
|
|
227
|
+
private setupPromptHandlers;
|
|
228
|
+
private resolveToolArgs;
|
|
229
|
+
private resolveResourceArgs;
|
|
230
|
+
private resolvePromptArgs;
|
|
231
|
+
private extractUriParams;
|
|
232
|
+
/**
|
|
233
|
+
* Start the MCP server
|
|
234
|
+
*/
|
|
235
|
+
start(): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Get the underlying MCP server instance
|
|
238
|
+
*/
|
|
239
|
+
getServer(): Server;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Create and start an MCP server from a decorated class
|
|
243
|
+
*/
|
|
244
|
+
declare function createMcpServer(target: Function, options?: McpRuntimeOptions): Promise<McpRuntimeServer>;
|
|
245
|
+
|
|
246
|
+
declare const VERSION = "0.1.0";
|
|
247
|
+
|
|
248
|
+
export { McpInput, McpParam, McpPrompt, McpPromptArg, type McpPromptOptions, McpResource, type McpResourceOptions, type McpRuntimeOptions, McpRuntimeServer, McpServer, type McpServerOptions, McpTool, type McpToolOptions, VERSION, createMcpServer, getMcpServers, getParamsMetadata, getPromptsMetadata, getResourcesMetadata, getServerMetadata, getToolsMetadata, isMcpServer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { ToolInputSchema, PromptArgument, McpParamMetadata, McpPromptMetadata, McpResourceMetadata, McpServerMetadata, McpToolMetadata } from '@mcp-weave/core';
|
|
2
|
+
export { METADATA_KEYS, McpParamMetadata, McpPromptMetadata, McpResourceMetadata, McpServerMetadata, McpToolMetadata, ScannedMetadata, extractMetadata } from '@mcp-weave/core';
|
|
3
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for @McpServer decorator
|
|
7
|
+
*/
|
|
8
|
+
interface McpServerOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Server name
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Server version (default: '1.0.0')
|
|
15
|
+
*/
|
|
16
|
+
version?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Server description
|
|
19
|
+
*/
|
|
20
|
+
description?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Marks a class as an MCP server
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* @McpServer({ name: 'my-service', version: '1.0.0' })
|
|
28
|
+
* export class MyController {
|
|
29
|
+
* // ...
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function McpServer(options: McpServerOptions): ClassDecorator;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Options for @McpTool decorator
|
|
37
|
+
*/
|
|
38
|
+
interface McpToolOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Tool name
|
|
41
|
+
*/
|
|
42
|
+
name: string;
|
|
43
|
+
/**
|
|
44
|
+
* Tool description
|
|
45
|
+
*/
|
|
46
|
+
description: string;
|
|
47
|
+
/**
|
|
48
|
+
* Input schema (JSON Schema)
|
|
49
|
+
*/
|
|
50
|
+
inputSchema?: ToolInputSchema;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Marks a method as an MCP tool
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* @McpTool({
|
|
58
|
+
* name: 'create_user',
|
|
59
|
+
* description: 'Creates a new user'
|
|
60
|
+
* })
|
|
61
|
+
* async createUser(@McpInput() input: CreateUserDto) {
|
|
62
|
+
* return { success: true };
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function McpTool(options: McpToolOptions): MethodDecorator;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Options for @McpResource decorator
|
|
70
|
+
*/
|
|
71
|
+
interface McpResourceOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Resource URI template (e.g., 'user://{userId}')
|
|
74
|
+
*/
|
|
75
|
+
uri: string;
|
|
76
|
+
/**
|
|
77
|
+
* Resource name
|
|
78
|
+
*/
|
|
79
|
+
name: string;
|
|
80
|
+
/**
|
|
81
|
+
* Resource description
|
|
82
|
+
*/
|
|
83
|
+
description?: string;
|
|
84
|
+
/**
|
|
85
|
+
* MIME type (default: 'application/json')
|
|
86
|
+
*/
|
|
87
|
+
mimeType?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Marks a method as an MCP resource
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* @McpResource({
|
|
95
|
+
* uri: 'user://{userId}',
|
|
96
|
+
* name: 'User Profile',
|
|
97
|
+
* mimeType: 'application/json'
|
|
98
|
+
* })
|
|
99
|
+
* async getUserProfile(@McpParam('userId') userId: string) {
|
|
100
|
+
* return { contents: [...] };
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function McpResource(options: McpResourceOptions): MethodDecorator;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Options for @McpPrompt decorator
|
|
108
|
+
*/
|
|
109
|
+
interface McpPromptOptions {
|
|
110
|
+
/**
|
|
111
|
+
* Prompt name
|
|
112
|
+
*/
|
|
113
|
+
name: string;
|
|
114
|
+
/**
|
|
115
|
+
* Prompt description
|
|
116
|
+
*/
|
|
117
|
+
description: string;
|
|
118
|
+
/**
|
|
119
|
+
* Prompt arguments
|
|
120
|
+
*/
|
|
121
|
+
arguments?: PromptArgument[];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Marks a method as an MCP prompt
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* @McpPrompt({
|
|
129
|
+
* name: 'welcome_email',
|
|
130
|
+
* description: 'Generate welcome email for new user'
|
|
131
|
+
* })
|
|
132
|
+
* async generateWelcomeEmail(
|
|
133
|
+
* @McpPromptArg('userName') userName: string
|
|
134
|
+
* ) {
|
|
135
|
+
* return { messages: [...] };
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare function McpPrompt(options: McpPromptOptions): MethodDecorator;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Injects the tool input
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* @McpTool({ name: 'create_user', description: 'Creates a user' })
|
|
147
|
+
* async createUser(@McpInput() input: CreateUserDto) {
|
|
148
|
+
* // input contains the tool arguments
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare function McpInput(): ParameterDecorator;
|
|
153
|
+
/**
|
|
154
|
+
* Injects a URI parameter from a resource
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* @McpResource({ uri: 'user://{userId}', name: 'User' })
|
|
159
|
+
* async getUser(@McpParam('userId') userId: string) {
|
|
160
|
+
* // userId is extracted from the URI
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function McpParam(name: string): ParameterDecorator;
|
|
165
|
+
/**
|
|
166
|
+
* Injects a prompt argument
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* @McpPrompt({ name: 'welcome', description: 'Welcome prompt' })
|
|
171
|
+
* async generateWelcome(@McpPromptArg('userName') userName: string) {
|
|
172
|
+
* // userName is the prompt argument
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function McpPromptArg(name: string): ParameterDecorator;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Check if a class has @McpServer decorator
|
|
180
|
+
*/
|
|
181
|
+
declare function isMcpServer(target: Function): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Get all MCP servers from an array of classes
|
|
184
|
+
*/
|
|
185
|
+
declare function getMcpServers(targets: Function[]): Function[];
|
|
186
|
+
/**
|
|
187
|
+
* Get server metadata from a class
|
|
188
|
+
*/
|
|
189
|
+
declare function getServerMetadata(target: Function): McpServerMetadata | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Get tools metadata from a class
|
|
192
|
+
*/
|
|
193
|
+
declare function getToolsMetadata(target: Function): McpToolMetadata[];
|
|
194
|
+
/**
|
|
195
|
+
* Get resources metadata from a class
|
|
196
|
+
*/
|
|
197
|
+
declare function getResourcesMetadata(target: Function): McpResourceMetadata[];
|
|
198
|
+
/**
|
|
199
|
+
* Get prompts metadata from a class
|
|
200
|
+
*/
|
|
201
|
+
declare function getPromptsMetadata(target: Function): McpPromptMetadata[];
|
|
202
|
+
/**
|
|
203
|
+
* Get params metadata from a class
|
|
204
|
+
*/
|
|
205
|
+
declare function getParamsMetadata(target: Function): McpParamMetadata[];
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Options for MCP runtime server
|
|
209
|
+
*/
|
|
210
|
+
interface McpRuntimeOptions {
|
|
211
|
+
/**
|
|
212
|
+
* Transport type
|
|
213
|
+
*/
|
|
214
|
+
transport?: 'stdio' | 'sse';
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Runtime MCP server that wraps a decorated class
|
|
218
|
+
*/
|
|
219
|
+
declare class McpRuntimeServer {
|
|
220
|
+
private server;
|
|
221
|
+
private instance;
|
|
222
|
+
private metadata;
|
|
223
|
+
constructor(target: Function, _options?: McpRuntimeOptions);
|
|
224
|
+
private setupHandlers;
|
|
225
|
+
private setupToolHandlers;
|
|
226
|
+
private setupResourceHandlers;
|
|
227
|
+
private setupPromptHandlers;
|
|
228
|
+
private resolveToolArgs;
|
|
229
|
+
private resolveResourceArgs;
|
|
230
|
+
private resolvePromptArgs;
|
|
231
|
+
private extractUriParams;
|
|
232
|
+
/**
|
|
233
|
+
* Start the MCP server
|
|
234
|
+
*/
|
|
235
|
+
start(): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Get the underlying MCP server instance
|
|
238
|
+
*/
|
|
239
|
+
getServer(): Server;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Create and start an MCP server from a decorated class
|
|
243
|
+
*/
|
|
244
|
+
declare function createMcpServer(target: Function, options?: McpRuntimeOptions): Promise<McpRuntimeServer>;
|
|
245
|
+
|
|
246
|
+
declare const VERSION = "0.1.0";
|
|
247
|
+
|
|
248
|
+
export { McpInput, McpParam, McpPrompt, McpPromptArg, type McpPromptOptions, McpResource, type McpResourceOptions, type McpRuntimeOptions, McpRuntimeServer, McpServer, type McpServerOptions, McpTool, type McpToolOptions, VERSION, createMcpServer, getMcpServers, getParamsMetadata, getPromptsMetadata, getResourcesMetadata, getServerMetadata, getToolsMetadata, isMcpServer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('reflect-metadata');
|
|
4
|
+
var core = require('@mcp-weave/core');
|
|
5
|
+
var index_js = require('@modelcontextprotocol/sdk/server/index.js');
|
|
6
|
+
var stdio_js = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
function McpServer(options) {
|
|
10
|
+
return (target) => {
|
|
11
|
+
const metadata = {
|
|
12
|
+
name: options.name,
|
|
13
|
+
version: options.version ?? "1.0.0",
|
|
14
|
+
description: options.description,
|
|
15
|
+
target
|
|
16
|
+
};
|
|
17
|
+
Reflect.defineMetadata(core.METADATA_KEYS.SERVER, metadata, target);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function McpTool(options) {
|
|
21
|
+
return (target, propertyKey, _descriptor) => {
|
|
22
|
+
const constructor = target.constructor;
|
|
23
|
+
const existingTools = Reflect.getMetadata(core.METADATA_KEYS.TOOLS, constructor) ?? [];
|
|
24
|
+
const metadata = {
|
|
25
|
+
name: options.name,
|
|
26
|
+
description: options.description,
|
|
27
|
+
inputSchema: options.inputSchema,
|
|
28
|
+
propertyKey,
|
|
29
|
+
target: constructor
|
|
30
|
+
};
|
|
31
|
+
Reflect.defineMetadata(core.METADATA_KEYS.TOOLS, [...existingTools, metadata], constructor);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function McpResource(options) {
|
|
35
|
+
return (target, propertyKey, _descriptor) => {
|
|
36
|
+
const constructor = target.constructor;
|
|
37
|
+
const existingResources = Reflect.getMetadata(core.METADATA_KEYS.RESOURCES, constructor) ?? [];
|
|
38
|
+
const metadata = {
|
|
39
|
+
uri: options.uri,
|
|
40
|
+
name: options.name,
|
|
41
|
+
description: options.description,
|
|
42
|
+
mimeType: options.mimeType ?? "application/json",
|
|
43
|
+
propertyKey,
|
|
44
|
+
target: constructor
|
|
45
|
+
};
|
|
46
|
+
Reflect.defineMetadata(core.METADATA_KEYS.RESOURCES, [...existingResources, metadata], constructor);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function McpPrompt(options) {
|
|
50
|
+
return (target, propertyKey, _descriptor) => {
|
|
51
|
+
const constructor = target.constructor;
|
|
52
|
+
const existingPrompts = Reflect.getMetadata(core.METADATA_KEYS.PROMPTS, constructor) ?? [];
|
|
53
|
+
const metadata = {
|
|
54
|
+
name: options.name,
|
|
55
|
+
description: options.description,
|
|
56
|
+
arguments: options.arguments,
|
|
57
|
+
propertyKey,
|
|
58
|
+
target: constructor
|
|
59
|
+
};
|
|
60
|
+
Reflect.defineMetadata(core.METADATA_KEYS.PROMPTS, [...existingPrompts, metadata], constructor);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function McpInput() {
|
|
64
|
+
return (target, propertyKey, parameterIndex) => {
|
|
65
|
+
if (!propertyKey) return;
|
|
66
|
+
const constructor = target.constructor;
|
|
67
|
+
const existingParams = Reflect.getMetadata(core.METADATA_KEYS.PARAMS, constructor) ?? [];
|
|
68
|
+
const metadata = {
|
|
69
|
+
type: "input",
|
|
70
|
+
parameterIndex,
|
|
71
|
+
propertyKey,
|
|
72
|
+
target: constructor
|
|
73
|
+
};
|
|
74
|
+
Reflect.defineMetadata(core.METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function McpParam(name) {
|
|
78
|
+
return (target, propertyKey, parameterIndex) => {
|
|
79
|
+
if (!propertyKey) return;
|
|
80
|
+
const constructor = target.constructor;
|
|
81
|
+
const existingParams = Reflect.getMetadata(core.METADATA_KEYS.PARAMS, constructor) ?? [];
|
|
82
|
+
const metadata = {
|
|
83
|
+
type: "param",
|
|
84
|
+
name,
|
|
85
|
+
parameterIndex,
|
|
86
|
+
propertyKey,
|
|
87
|
+
target: constructor
|
|
88
|
+
};
|
|
89
|
+
Reflect.defineMetadata(core.METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function McpPromptArg(name) {
|
|
93
|
+
return (target, propertyKey, parameterIndex) => {
|
|
94
|
+
if (!propertyKey) return;
|
|
95
|
+
const constructor = target.constructor;
|
|
96
|
+
const existingParams = Reflect.getMetadata(core.METADATA_KEYS.PARAMS, constructor) ?? [];
|
|
97
|
+
const metadata = {
|
|
98
|
+
type: "promptArg",
|
|
99
|
+
name,
|
|
100
|
+
parameterIndex,
|
|
101
|
+
propertyKey,
|
|
102
|
+
target: constructor
|
|
103
|
+
};
|
|
104
|
+
Reflect.defineMetadata(core.METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function isMcpServer(target) {
|
|
108
|
+
return Reflect.hasMetadata(core.METADATA_KEYS.SERVER, target);
|
|
109
|
+
}
|
|
110
|
+
function getMcpServers(targets) {
|
|
111
|
+
return targets.filter(isMcpServer);
|
|
112
|
+
}
|
|
113
|
+
function getServerMetadata(target) {
|
|
114
|
+
return Reflect.getMetadata(core.METADATA_KEYS.SERVER, target);
|
|
115
|
+
}
|
|
116
|
+
function getToolsMetadata(target) {
|
|
117
|
+
return Reflect.getMetadata(core.METADATA_KEYS.TOOLS, target) ?? [];
|
|
118
|
+
}
|
|
119
|
+
function getResourcesMetadata(target) {
|
|
120
|
+
return Reflect.getMetadata(core.METADATA_KEYS.RESOURCES, target) ?? [];
|
|
121
|
+
}
|
|
122
|
+
function getPromptsMetadata(target) {
|
|
123
|
+
return Reflect.getMetadata(core.METADATA_KEYS.PROMPTS, target) ?? [];
|
|
124
|
+
}
|
|
125
|
+
function getParamsMetadata(target) {
|
|
126
|
+
return Reflect.getMetadata(core.METADATA_KEYS.PARAMS, target) ?? [];
|
|
127
|
+
}
|
|
128
|
+
var McpRuntimeServer = class {
|
|
129
|
+
server;
|
|
130
|
+
instance;
|
|
131
|
+
metadata;
|
|
132
|
+
constructor(target, _options = {}) {
|
|
133
|
+
this.metadata = core.extractMetadata(target);
|
|
134
|
+
if (!this.metadata.server) {
|
|
135
|
+
throw new Error(`Class ${target.name} is not decorated with @McpServer`);
|
|
136
|
+
}
|
|
137
|
+
this.server = new index_js.Server(
|
|
138
|
+
{
|
|
139
|
+
name: this.metadata.server.name,
|
|
140
|
+
version: this.metadata.server.version ?? "1.0.0"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
capabilities: {
|
|
144
|
+
tools: this.metadata.tools.length > 0 ? {} : void 0,
|
|
145
|
+
resources: this.metadata.resources.length > 0 ? {} : void 0,
|
|
146
|
+
prompts: this.metadata.prompts.length > 0 ? {} : void 0
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
this.instance = new target();
|
|
151
|
+
this.setupHandlers();
|
|
152
|
+
}
|
|
153
|
+
setupHandlers() {
|
|
154
|
+
this.setupToolHandlers();
|
|
155
|
+
this.setupResourceHandlers();
|
|
156
|
+
this.setupPromptHandlers();
|
|
157
|
+
}
|
|
158
|
+
setupToolHandlers() {
|
|
159
|
+
const tools = this.metadata.tools;
|
|
160
|
+
if (tools.length === 0) return;
|
|
161
|
+
this.server.setRequestHandler({ method: "tools/list" }, async () => ({
|
|
162
|
+
tools: tools.map((tool) => ({
|
|
163
|
+
name: tool.name,
|
|
164
|
+
description: tool.description,
|
|
165
|
+
inputSchema: tool.inputSchema ?? { type: "object", properties: {} }
|
|
166
|
+
}))
|
|
167
|
+
}));
|
|
168
|
+
this.server.setRequestHandler({ method: "tools/call" }, async (request) => {
|
|
169
|
+
const toolName = request.params.name;
|
|
170
|
+
const tool = tools.find((t) => t.name === toolName);
|
|
171
|
+
if (!tool) {
|
|
172
|
+
throw new Error(`Unknown tool: ${toolName}`);
|
|
173
|
+
}
|
|
174
|
+
const method = this.instance[tool.propertyKey];
|
|
175
|
+
if (typeof method !== "function") {
|
|
176
|
+
throw new Error(`Method ${String(tool.propertyKey)} not found`);
|
|
177
|
+
}
|
|
178
|
+
const args = this.resolveToolArgs(tool.propertyKey, request.params.arguments ?? {});
|
|
179
|
+
const result = await method.apply(this.instance, args);
|
|
180
|
+
return {
|
|
181
|
+
content: [
|
|
182
|
+
{
|
|
183
|
+
type: "text",
|
|
184
|
+
text: typeof result === "string" ? result : JSON.stringify(result)
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
setupResourceHandlers() {
|
|
191
|
+
const resources = this.metadata.resources;
|
|
192
|
+
if (resources.length === 0) return;
|
|
193
|
+
this.server.setRequestHandler({ method: "resources/list" }, async () => ({
|
|
194
|
+
resources: resources.map((resource) => ({
|
|
195
|
+
uri: resource.uri,
|
|
196
|
+
name: resource.name,
|
|
197
|
+
description: resource.description,
|
|
198
|
+
mimeType: resource.mimeType
|
|
199
|
+
}))
|
|
200
|
+
}));
|
|
201
|
+
this.server.setRequestHandler({ method: "resources/read" }, async (request) => {
|
|
202
|
+
const uri = request.params.uri;
|
|
203
|
+
for (const resource of resources) {
|
|
204
|
+
const params = this.extractUriParams(resource.uri, uri);
|
|
205
|
+
if (params) {
|
|
206
|
+
const method = this.instance[resource.propertyKey];
|
|
207
|
+
if (typeof method !== "function") {
|
|
208
|
+
throw new Error(`Method ${String(resource.propertyKey)} not found`);
|
|
209
|
+
}
|
|
210
|
+
const args = this.resolveResourceArgs(resource.propertyKey, params);
|
|
211
|
+
return await method.apply(this.instance, args);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
throw new Error(`Resource not found: ${uri}`);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
setupPromptHandlers() {
|
|
218
|
+
const prompts = this.metadata.prompts;
|
|
219
|
+
if (prompts.length === 0) return;
|
|
220
|
+
this.server.setRequestHandler({ method: "prompts/list" }, async () => ({
|
|
221
|
+
prompts: prompts.map((prompt) => ({
|
|
222
|
+
name: prompt.name,
|
|
223
|
+
description: prompt.description,
|
|
224
|
+
arguments: prompt.arguments ?? []
|
|
225
|
+
}))
|
|
226
|
+
}));
|
|
227
|
+
this.server.setRequestHandler({ method: "prompts/get" }, async (request) => {
|
|
228
|
+
const promptName = request.params.name;
|
|
229
|
+
const prompt = prompts.find((p) => p.name === promptName);
|
|
230
|
+
if (!prompt) {
|
|
231
|
+
throw new Error(`Unknown prompt: ${promptName}`);
|
|
232
|
+
}
|
|
233
|
+
const method = this.instance[prompt.propertyKey];
|
|
234
|
+
if (typeof method !== "function") {
|
|
235
|
+
throw new Error(`Method ${String(prompt.propertyKey)} not found`);
|
|
236
|
+
}
|
|
237
|
+
const args = this.resolvePromptArgs(prompt.propertyKey, request.params.arguments ?? {});
|
|
238
|
+
return await method.apply(this.instance, args);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
resolveToolArgs(propertyKey, input) {
|
|
242
|
+
const params = this.metadata.params.filter(
|
|
243
|
+
(p) => p.propertyKey === propertyKey && p.type === "input"
|
|
244
|
+
);
|
|
245
|
+
if (params.length === 0) {
|
|
246
|
+
return [input];
|
|
247
|
+
}
|
|
248
|
+
const args = [];
|
|
249
|
+
for (const param of params) {
|
|
250
|
+
args[param.parameterIndex] = input;
|
|
251
|
+
}
|
|
252
|
+
return args;
|
|
253
|
+
}
|
|
254
|
+
resolveResourceArgs(propertyKey, uriParams) {
|
|
255
|
+
const params = this.metadata.params.filter(
|
|
256
|
+
(p) => p.propertyKey === propertyKey && p.type === "param"
|
|
257
|
+
);
|
|
258
|
+
const args = [];
|
|
259
|
+
for (const param of params) {
|
|
260
|
+
if (param.name) {
|
|
261
|
+
args[param.parameterIndex] = uriParams[param.name];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return args;
|
|
265
|
+
}
|
|
266
|
+
resolvePromptArgs(propertyKey, promptArgs) {
|
|
267
|
+
const params = this.metadata.params.filter(
|
|
268
|
+
(p) => p.propertyKey === propertyKey && p.type === "promptArg"
|
|
269
|
+
);
|
|
270
|
+
const args = [];
|
|
271
|
+
for (const param of params) {
|
|
272
|
+
if (param.name) {
|
|
273
|
+
args[param.parameterIndex] = promptArgs[param.name];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return args;
|
|
277
|
+
}
|
|
278
|
+
extractUriParams(template, uri) {
|
|
279
|
+
const paramNames = [];
|
|
280
|
+
const regexStr = template.replace(/\{(\w+)\}/g, (_, name) => {
|
|
281
|
+
paramNames.push(name);
|
|
282
|
+
return "([^/]+)";
|
|
283
|
+
});
|
|
284
|
+
const regex = new RegExp(`^${regexStr}$`);
|
|
285
|
+
const match = uri.match(regex);
|
|
286
|
+
if (!match) return null;
|
|
287
|
+
const params = {};
|
|
288
|
+
paramNames.forEach((name, index) => {
|
|
289
|
+
params[name] = match[index + 1] ?? "";
|
|
290
|
+
});
|
|
291
|
+
return params;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Start the MCP server
|
|
295
|
+
*/
|
|
296
|
+
async start() {
|
|
297
|
+
const transport = new stdio_js.StdioServerTransport();
|
|
298
|
+
await this.server.connect(transport);
|
|
299
|
+
console.error(`MCP server '${this.metadata.server?.name}' started on stdio`);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Get the underlying MCP server instance
|
|
303
|
+
*/
|
|
304
|
+
getServer() {
|
|
305
|
+
return this.server;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
async function createMcpServer(target, options) {
|
|
309
|
+
const server = new McpRuntimeServer(target, options);
|
|
310
|
+
await server.start();
|
|
311
|
+
return server;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// src/index.ts
|
|
315
|
+
var VERSION = "0.1.0";
|
|
316
|
+
|
|
317
|
+
Object.defineProperty(exports, "METADATA_KEYS", {
|
|
318
|
+
enumerable: true,
|
|
319
|
+
get: function () { return core.METADATA_KEYS; }
|
|
320
|
+
});
|
|
321
|
+
Object.defineProperty(exports, "extractMetadata", {
|
|
322
|
+
enumerable: true,
|
|
323
|
+
get: function () { return core.extractMetadata; }
|
|
324
|
+
});
|
|
325
|
+
exports.McpInput = McpInput;
|
|
326
|
+
exports.McpParam = McpParam;
|
|
327
|
+
exports.McpPrompt = McpPrompt;
|
|
328
|
+
exports.McpPromptArg = McpPromptArg;
|
|
329
|
+
exports.McpResource = McpResource;
|
|
330
|
+
exports.McpRuntimeServer = McpRuntimeServer;
|
|
331
|
+
exports.McpServer = McpServer;
|
|
332
|
+
exports.McpTool = McpTool;
|
|
333
|
+
exports.VERSION = VERSION;
|
|
334
|
+
exports.createMcpServer = createMcpServer;
|
|
335
|
+
exports.getMcpServers = getMcpServers;
|
|
336
|
+
exports.getParamsMetadata = getParamsMetadata;
|
|
337
|
+
exports.getPromptsMetadata = getPromptsMetadata;
|
|
338
|
+
exports.getResourcesMetadata = getResourcesMetadata;
|
|
339
|
+
exports.getServerMetadata = getServerMetadata;
|
|
340
|
+
exports.getToolsMetadata = getToolsMetadata;
|
|
341
|
+
exports.isMcpServer = isMcpServer;
|
|
342
|
+
//# sourceMappingURL=index.js.map
|
|
343
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/decorators/mcp-server.ts","../src/decorators/mcp-tool.ts","../src/decorators/mcp-resource.ts","../src/decorators/mcp-prompt.ts","../src/decorators/params.ts","../src/metadata/storage.ts","../src/runtime/server.ts","../src/index.ts"],"names":["METADATA_KEYS","extractMetadata","Server","StdioServerTransport"],"mappings":";;;;;;;;AAmCO,SAAS,UAAU,OAAA,EAA2C;AACnE,EAAA,OAAO,CAAC,MAAA,KAAqB;AAC3B,IAAA,MAAM,QAAA,GAA8B;AAAA,MAClC,MAAM,OAAA,CAAQ,IAAA;AAAA,MACd,OAAA,EAAS,QAAQ,OAAA,IAAW,OAAA;AAAA,MAC5B,aAAa,OAAA,CAAQ,WAAA;AAAA,MACrB;AAAA,KACF;AAEA,IAAA,OAAA,CAAQ,cAAA,CAAeA,kBAAA,CAAc,MAAA,EAAQ,QAAA,EAAU,MAAM,CAAA;AAAA,EAC/D,CAAA;AACF;ACRO,SAAS,QAAQ,OAAA,EAA0C;AAChE,EAAA,OAAO,CAAC,MAAA,EAAgB,WAAA,EAA8B,WAAA,KAAoC;AACxF,IAAA,MAAM,cAAc,MAAA,CAAO,WAAA;AAE3B,IAAA,MAAM,gBACJ,OAAA,CAAQ,WAAA,CAAYA,mBAAc,KAAA,EAAO,WAAW,KAAK,EAAC;AAE5D,IAAA,MAAM,QAAA,GAA4B;AAAA,MAChC,MAAM,OAAA,CAAQ,IAAA;AAAA,MACd,aAAa,OAAA,CAAQ,WAAA;AAAA,MACrB,aAAa,OAAA,CAAQ,WAAA;AAAA,MACrB,WAAA;AAAA,MACA,MAAA,EAAQ;AAAA,KACV;AAEA,IAAA,OAAA,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AAA,IAAK,EAAA;AAAA,IACrC,CAAC,CAAA;AAED,IAAA,OAAO,MAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAA,GAAuB;AAC3B,IAAA,MAAM,SAAA,GAAY,IAAIC,6BAAA,EAAqB;AAC3C,IAAA,MAAM,IAAA,CAAK,MAAA,CAAO,OAAA,CAAQ,SAAS,CAAA;AACnC,IAAA,OAAA,CAAQ,MAAM,CAAA,YAAA,EAAe,IAAA,CAAK,QAAA,CAAS,MAAA,EAAQ,IAAI,CAAA,kBAAA,CAAoB,CAAA;AAAA,EAC7E;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA,GAAoB;AAClB,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AACF;AAKA,eAAsB,eAAA,CACpB,QACA,OAAA,EAC2B;AAC3B,EAAA,MAAM,MAAA,GAAS,IAAI,gBAAA,CAAiB,MAAA,EAAQ,OAAO,CAAA;AACnD,EAAA,MAAM,OAAO,KAAA,EAAM;AACnB,EAAA,OAAO,MAAA;AACT;;;ACjPO,IAAM,OAAA,GAAU","file":"index.js","sourcesContent":["import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpServerMetadata } from '@mcp-weave/core';\n\n/**\n * Options for @McpServer decorator\n */\nexport interface McpServerOptions {\n /**\n * Server name\n */\n name: string;\n\n /**\n * Server version (default: '1.0.0')\n */\n version?: string;\n\n /**\n * Server description\n */\n description?: string;\n}\n\n/**\n * Marks a class as an MCP server\n *\n * @example\n * ```typescript\n * @McpServer({ name: 'my-service', version: '1.0.0' })\n * export class MyController {\n * // ...\n * }\n * ```\n */\nexport function McpServer(options: McpServerOptions): ClassDecorator {\n return (target: Function) => {\n const metadata: McpServerMetadata = {\n name: options.name,\n version: options.version ?? '1.0.0',\n description: options.description,\n target,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.SERVER, metadata, target);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpToolMetadata, ToolInputSchema } from '@mcp-weave/core';\n\n/**\n * Options for @McpTool decorator\n */\nexport interface McpToolOptions {\n /**\n * Tool name\n */\n name: string;\n\n /**\n * Tool description\n */\n description: string;\n\n /**\n * Input schema (JSON Schema)\n */\n inputSchema?: ToolInputSchema;\n}\n\n/**\n * Marks a method as an MCP tool\n *\n * @example\n * ```typescript\n * @McpTool({\n * name: 'create_user',\n * description: 'Creates a new user'\n * })\n * async createUser(@McpInput() input: CreateUserDto) {\n * return { success: true };\n * }\n * ```\n */\nexport function McpTool(options: McpToolOptions): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n\n const existingTools: McpToolMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.TOOLS, constructor) ?? [];\n\n const metadata: McpToolMetadata = {\n name: options.name,\n description: options.description,\n inputSchema: options.inputSchema,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.TOOLS, [...existingTools, metadata], constructor);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpResourceMetadata } from '@mcp-weave/core';\n\n/**\n * Options for @McpResource decorator\n */\nexport interface McpResourceOptions {\n /**\n * Resource URI template (e.g., 'user://{userId}')\n */\n uri: string;\n\n /**\n * Resource name\n */\n name: string;\n\n /**\n * Resource description\n */\n description?: string;\n\n /**\n * MIME type (default: 'application/json')\n */\n mimeType?: string;\n}\n\n/**\n * Marks a method as an MCP resource\n *\n * @example\n * ```typescript\n * @McpResource({\n * uri: 'user://{userId}',\n * name: 'User Profile',\n * mimeType: 'application/json'\n * })\n * async getUserProfile(@McpParam('userId') userId: string) {\n * return { contents: [...] };\n * }\n * ```\n */\nexport function McpResource(options: McpResourceOptions): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n\n const existingResources: McpResourceMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.RESOURCES, constructor) ?? [];\n\n const metadata: McpResourceMetadata = {\n uri: options.uri,\n name: options.name,\n description: options.description,\n mimeType: options.mimeType ?? 'application/json',\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.RESOURCES, [...existingResources, metadata], constructor);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpPromptMetadata, PromptArgument } from '@mcp-weave/core';\n\n/**\n * Options for @McpPrompt decorator\n */\nexport interface McpPromptOptions {\n /**\n * Prompt name\n */\n name: string;\n\n /**\n * Prompt description\n */\n description: string;\n\n /**\n * Prompt arguments\n */\n arguments?: PromptArgument[];\n}\n\n/**\n * Marks a method as an MCP prompt\n *\n * @example\n * ```typescript\n * @McpPrompt({\n * name: 'welcome_email',\n * description: 'Generate welcome email for new user'\n * })\n * async generateWelcomeEmail(\n * @McpPromptArg('userName') userName: string\n * ) {\n * return { messages: [...] };\n * }\n * ```\n */\nexport function McpPrompt(options: McpPromptOptions): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n\n const existingPrompts: McpPromptMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.PROMPTS, constructor) ?? [];\n\n const metadata: McpPromptMetadata = {\n name: options.name,\n description: options.description,\n arguments: options.arguments,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.PROMPTS, [...existingPrompts, metadata], constructor);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpParamMetadata } from '@mcp-weave/core';\n\n/**\n * Injects the tool input\n *\n * @example\n * ```typescript\n * @McpTool({ name: 'create_user', description: 'Creates a user' })\n * async createUser(@McpInput() input: CreateUserDto) {\n * // input contains the tool arguments\n * }\n * ```\n */\nexport function McpInput(): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n if (!propertyKey) return;\n\n const constructor = target.constructor;\n const existingParams: McpParamMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.PARAMS, constructor) ?? [];\n\n const metadata: McpParamMetadata = {\n type: 'input',\n parameterIndex,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);\n };\n}\n\n/**\n * Injects a URI parameter from a resource\n *\n * @example\n * ```typescript\n * @McpResource({ uri: 'user://{userId}', name: 'User' })\n * async getUser(@McpParam('userId') userId: string) {\n * // userId is extracted from the URI\n * }\n * ```\n */\nexport function McpParam(name: string): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n if (!propertyKey) return;\n\n const constructor = target.constructor;\n const existingParams: McpParamMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.PARAMS, constructor) ?? [];\n\n const metadata: McpParamMetadata = {\n type: 'param',\n name,\n parameterIndex,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);\n };\n}\n\n/**\n * Injects a prompt argument\n *\n * @example\n * ```typescript\n * @McpPrompt({ name: 'welcome', description: 'Welcome prompt' })\n * async generateWelcome(@McpPromptArg('userName') userName: string) {\n * // userName is the prompt argument\n * }\n * ```\n */\nexport function McpPromptArg(name: string): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n if (!propertyKey) return;\n\n const constructor = target.constructor;\n const existingParams: McpParamMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.PARAMS, constructor) ?? [];\n\n const metadata: McpParamMetadata = {\n type: 'promptArg',\n name,\n parameterIndex,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS, extractMetadata, type ScannedMetadata } from '@mcp-weave/core';\nimport type {\n McpServerMetadata,\n McpToolMetadata,\n McpResourceMetadata,\n McpPromptMetadata,\n McpParamMetadata,\n} from '@mcp-weave/core';\n\n// Re-export for convenience\nexport { METADATA_KEYS, extractMetadata };\nexport type {\n ScannedMetadata,\n McpServerMetadata,\n McpToolMetadata,\n McpResourceMetadata,\n McpPromptMetadata,\n McpParamMetadata,\n};\n\n/**\n * Check if a class has @McpServer decorator\n */\nexport function isMcpServer(target: Function): boolean {\n return Reflect.hasMetadata(METADATA_KEYS.SERVER, target);\n}\n\n/**\n * Get all MCP servers from an array of classes\n */\nexport function getMcpServers(targets: Function[]): Function[] {\n return targets.filter(isMcpServer);\n}\n\n/**\n * Get server metadata from a class\n */\nexport function getServerMetadata(target: Function): McpServerMetadata | undefined {\n return Reflect.getMetadata(METADATA_KEYS.SERVER, target);\n}\n\n/**\n * Get tools metadata from a class\n */\nexport function getToolsMetadata(target: Function): McpToolMetadata[] {\n return Reflect.getMetadata(METADATA_KEYS.TOOLS, target) ?? [];\n}\n\n/**\n * Get resources metadata from a class\n */\nexport function getResourcesMetadata(target: Function): McpResourceMetadata[] {\n return Reflect.getMetadata(METADATA_KEYS.RESOURCES, target) ?? [];\n}\n\n/**\n * Get prompts metadata from a class\n */\nexport function getPromptsMetadata(target: Function): McpPromptMetadata[] {\n return Reflect.getMetadata(METADATA_KEYS.PROMPTS, target) ?? [];\n}\n\n/**\n * Get params metadata from a class\n */\nexport function getParamsMetadata(target: Function): McpParamMetadata[] {\n return Reflect.getMetadata(METADATA_KEYS.PARAMS, target) ?? [];\n}\n","import { Server } from '@modelcontextprotocol/sdk/server/index.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\n\nimport { extractMetadata } from '../metadata/storage.js';\n\n/**\n * Options for MCP runtime server\n */\nexport interface McpRuntimeOptions {\n /**\n * Transport type\n */\n transport?: 'stdio' | 'sse';\n}\n\n/**\n * Runtime MCP server that wraps a decorated class\n */\nexport class McpRuntimeServer {\n private server: Server;\n private instance: any;\n private metadata;\n\n constructor(target: Function, _options: McpRuntimeOptions = {}) {\n this.metadata = extractMetadata(target);\n\n if (!this.metadata.server) {\n throw new Error(`Class ${target.name} is not decorated with @McpServer`);\n }\n\n this.server = new Server(\n {\n name: this.metadata.server.name,\n version: this.metadata.server.version ?? '1.0.0',\n },\n {\n capabilities: {\n tools: this.metadata.tools.length > 0 ? {} : undefined,\n resources: this.metadata.resources.length > 0 ? {} : undefined,\n prompts: this.metadata.prompts.length > 0 ? {} : undefined,\n },\n }\n );\n\n // Create instance of the target class\n this.instance = new (target as any)();\n\n this.setupHandlers();\n }\n\n private setupHandlers() {\n this.setupToolHandlers();\n this.setupResourceHandlers();\n this.setupPromptHandlers();\n }\n\n private setupToolHandlers() {\n const tools = this.metadata.tools;\n if (tools.length === 0) return;\n\n // List tools\n this.server.setRequestHandler({ method: 'tools/list' } as any, async () => ({\n tools: tools.map(tool => ({\n name: tool.name,\n description: tool.description,\n inputSchema: tool.inputSchema ?? { type: 'object' as const, properties: {} },\n })),\n }));\n\n // Call tool\n this.server.setRequestHandler({ method: 'tools/call' } as any, async (request: any) => {\n const toolName = request.params.name;\n const tool = tools.find(t => t.name === toolName);\n\n if (!tool) {\n throw new Error(`Unknown tool: ${toolName}`);\n }\n\n const method = this.instance[tool.propertyKey];\n if (typeof method !== 'function') {\n throw new Error(`Method ${String(tool.propertyKey)} not found`);\n }\n\n const args = this.resolveToolArgs(tool.propertyKey, request.params.arguments ?? {});\n const result = await method.apply(this.instance, args);\n\n return {\n content: [\n {\n type: 'text',\n text: typeof result === 'string' ? result : JSON.stringify(result),\n },\n ],\n };\n });\n }\n\n private setupResourceHandlers() {\n const resources = this.metadata.resources;\n if (resources.length === 0) return;\n\n // List resources\n this.server.setRequestHandler({ method: 'resources/list' } as any, async () => ({\n resources: resources.map(resource => ({\n uri: resource.uri,\n name: resource.name,\n description: resource.description,\n mimeType: resource.mimeType,\n })),\n }));\n\n // Read resource\n this.server.setRequestHandler({ method: 'resources/read' } as any, async (request: any) => {\n const uri = request.params.uri as string;\n\n // Find matching resource\n for (const resource of resources) {\n const params = this.extractUriParams(resource.uri, uri);\n if (params) {\n const method = this.instance[resource.propertyKey];\n if (typeof method !== 'function') {\n throw new Error(`Method ${String(resource.propertyKey)} not found`);\n }\n\n const args = this.resolveResourceArgs(resource.propertyKey, params);\n return await method.apply(this.instance, args);\n }\n }\n\n throw new Error(`Resource not found: ${uri}`);\n });\n }\n\n private setupPromptHandlers() {\n const prompts = this.metadata.prompts;\n if (prompts.length === 0) return;\n\n // List prompts\n this.server.setRequestHandler({ method: 'prompts/list' } as any, async () => ({\n prompts: prompts.map(prompt => ({\n name: prompt.name,\n description: prompt.description,\n arguments: prompt.arguments ?? [],\n })),\n }));\n\n // Get prompt\n this.server.setRequestHandler({ method: 'prompts/get' } as any, async (request: any) => {\n const promptName = request.params.name;\n const prompt = prompts.find(p => p.name === promptName);\n\n if (!prompt) {\n throw new Error(`Unknown prompt: ${promptName}`);\n }\n\n const method = this.instance[prompt.propertyKey];\n if (typeof method !== 'function') {\n throw new Error(`Method ${String(prompt.propertyKey)} not found`);\n }\n\n const args = this.resolvePromptArgs(prompt.propertyKey, request.params.arguments ?? {});\n return await method.apply(this.instance, args);\n });\n }\n\n private resolveToolArgs(propertyKey: string | symbol, input: Record<string, any>): any[] {\n const params = this.metadata.params.filter(\n p => p.propertyKey === propertyKey && p.type === 'input'\n );\n\n if (params.length === 0) {\n return [input];\n }\n\n const args: any[] = [];\n for (const param of params) {\n args[param.parameterIndex] = input;\n }\n return args;\n }\n\n private resolveResourceArgs(\n propertyKey: string | symbol,\n uriParams: Record<string, string>\n ): any[] {\n const params = this.metadata.params.filter(\n p => p.propertyKey === propertyKey && p.type === 'param'\n );\n\n const args: any[] = [];\n for (const param of params) {\n if (param.name) {\n args[param.parameterIndex] = uriParams[param.name];\n }\n }\n return args;\n }\n\n private resolvePromptArgs(propertyKey: string | symbol, promptArgs: Record<string, any>): any[] {\n const params = this.metadata.params.filter(\n p => p.propertyKey === propertyKey && p.type === 'promptArg'\n );\n\n const args: any[] = [];\n for (const param of params) {\n if (param.name) {\n args[param.parameterIndex] = promptArgs[param.name];\n }\n }\n return args;\n }\n\n private extractUriParams(template: string, uri: string): Record<string, string> | null {\n // Convert template to regex: user://{userId} -> user://([^/]+)\n const paramNames: string[] = [];\n const regexStr = template.replace(/\\{(\\w+)\\}/g, (_, name) => {\n paramNames.push(name);\n return '([^/]+)';\n });\n\n const regex = new RegExp(`^${regexStr}$`);\n const match = uri.match(regex);\n\n if (!match) return null;\n\n const params: Record<string, string> = {};\n paramNames.forEach((name, index) => {\n params[name] = match[index + 1] ?? '';\n });\n\n return params;\n }\n\n /**\n * Start the MCP server\n */\n async start(): Promise<void> {\n const transport = new StdioServerTransport();\n await this.server.connect(transport);\n console.error(`MCP server '${this.metadata.server?.name}' started on stdio`);\n }\n\n /**\n * Get the underlying MCP server instance\n */\n getServer(): Server {\n return this.server;\n }\n}\n\n/**\n * Create and start an MCP server from a decorated class\n */\nexport async function createMcpServer(\n target: Function,\n options?: McpRuntimeOptions\n): Promise<McpRuntimeServer> {\n const server = new McpRuntimeServer(target, options);\n await server.start();\n return server;\n}\n","// @mcp-weave/nestjs\n// NestJS integration for MCP-Weave\n\nimport 'reflect-metadata';\n\n// Decorators\nexport * from './decorators/mcp-server.js';\nexport * from './decorators/mcp-tool.js';\nexport * from './decorators/mcp-resource.js';\nexport * from './decorators/mcp-prompt.js';\nexport * from './decorators/params.js';\n\n// Metadata\nexport * from './metadata/storage.js';\n\n// Runtime\nexport * from './runtime/server.js';\n\n// Version\nexport const VERSION = '0.1.0';\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { METADATA_KEYS, extractMetadata } from '@mcp-weave/core';
|
|
3
|
+
export { METADATA_KEYS, extractMetadata } from '@mcp-weave/core';
|
|
4
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
6
|
+
|
|
7
|
+
// src/index.ts
|
|
8
|
+
function McpServer(options) {
|
|
9
|
+
return (target) => {
|
|
10
|
+
const metadata = {
|
|
11
|
+
name: options.name,
|
|
12
|
+
version: options.version ?? "1.0.0",
|
|
13
|
+
description: options.description,
|
|
14
|
+
target
|
|
15
|
+
};
|
|
16
|
+
Reflect.defineMetadata(METADATA_KEYS.SERVER, metadata, target);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function McpTool(options) {
|
|
20
|
+
return (target, propertyKey, _descriptor) => {
|
|
21
|
+
const constructor = target.constructor;
|
|
22
|
+
const existingTools = Reflect.getMetadata(METADATA_KEYS.TOOLS, constructor) ?? [];
|
|
23
|
+
const metadata = {
|
|
24
|
+
name: options.name,
|
|
25
|
+
description: options.description,
|
|
26
|
+
inputSchema: options.inputSchema,
|
|
27
|
+
propertyKey,
|
|
28
|
+
target: constructor
|
|
29
|
+
};
|
|
30
|
+
Reflect.defineMetadata(METADATA_KEYS.TOOLS, [...existingTools, metadata], constructor);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function McpResource(options) {
|
|
34
|
+
return (target, propertyKey, _descriptor) => {
|
|
35
|
+
const constructor = target.constructor;
|
|
36
|
+
const existingResources = Reflect.getMetadata(METADATA_KEYS.RESOURCES, constructor) ?? [];
|
|
37
|
+
const metadata = {
|
|
38
|
+
uri: options.uri,
|
|
39
|
+
name: options.name,
|
|
40
|
+
description: options.description,
|
|
41
|
+
mimeType: options.mimeType ?? "application/json",
|
|
42
|
+
propertyKey,
|
|
43
|
+
target: constructor
|
|
44
|
+
};
|
|
45
|
+
Reflect.defineMetadata(METADATA_KEYS.RESOURCES, [...existingResources, metadata], constructor);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function McpPrompt(options) {
|
|
49
|
+
return (target, propertyKey, _descriptor) => {
|
|
50
|
+
const constructor = target.constructor;
|
|
51
|
+
const existingPrompts = Reflect.getMetadata(METADATA_KEYS.PROMPTS, constructor) ?? [];
|
|
52
|
+
const metadata = {
|
|
53
|
+
name: options.name,
|
|
54
|
+
description: options.description,
|
|
55
|
+
arguments: options.arguments,
|
|
56
|
+
propertyKey,
|
|
57
|
+
target: constructor
|
|
58
|
+
};
|
|
59
|
+
Reflect.defineMetadata(METADATA_KEYS.PROMPTS, [...existingPrompts, metadata], constructor);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function McpInput() {
|
|
63
|
+
return (target, propertyKey, parameterIndex) => {
|
|
64
|
+
if (!propertyKey) return;
|
|
65
|
+
const constructor = target.constructor;
|
|
66
|
+
const existingParams = Reflect.getMetadata(METADATA_KEYS.PARAMS, constructor) ?? [];
|
|
67
|
+
const metadata = {
|
|
68
|
+
type: "input",
|
|
69
|
+
parameterIndex,
|
|
70
|
+
propertyKey,
|
|
71
|
+
target: constructor
|
|
72
|
+
};
|
|
73
|
+
Reflect.defineMetadata(METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function McpParam(name) {
|
|
77
|
+
return (target, propertyKey, parameterIndex) => {
|
|
78
|
+
if (!propertyKey) return;
|
|
79
|
+
const constructor = target.constructor;
|
|
80
|
+
const existingParams = Reflect.getMetadata(METADATA_KEYS.PARAMS, constructor) ?? [];
|
|
81
|
+
const metadata = {
|
|
82
|
+
type: "param",
|
|
83
|
+
name,
|
|
84
|
+
parameterIndex,
|
|
85
|
+
propertyKey,
|
|
86
|
+
target: constructor
|
|
87
|
+
};
|
|
88
|
+
Reflect.defineMetadata(METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function McpPromptArg(name) {
|
|
92
|
+
return (target, propertyKey, parameterIndex) => {
|
|
93
|
+
if (!propertyKey) return;
|
|
94
|
+
const constructor = target.constructor;
|
|
95
|
+
const existingParams = Reflect.getMetadata(METADATA_KEYS.PARAMS, constructor) ?? [];
|
|
96
|
+
const metadata = {
|
|
97
|
+
type: "promptArg",
|
|
98
|
+
name,
|
|
99
|
+
parameterIndex,
|
|
100
|
+
propertyKey,
|
|
101
|
+
target: constructor
|
|
102
|
+
};
|
|
103
|
+
Reflect.defineMetadata(METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function isMcpServer(target) {
|
|
107
|
+
return Reflect.hasMetadata(METADATA_KEYS.SERVER, target);
|
|
108
|
+
}
|
|
109
|
+
function getMcpServers(targets) {
|
|
110
|
+
return targets.filter(isMcpServer);
|
|
111
|
+
}
|
|
112
|
+
function getServerMetadata(target) {
|
|
113
|
+
return Reflect.getMetadata(METADATA_KEYS.SERVER, target);
|
|
114
|
+
}
|
|
115
|
+
function getToolsMetadata(target) {
|
|
116
|
+
return Reflect.getMetadata(METADATA_KEYS.TOOLS, target) ?? [];
|
|
117
|
+
}
|
|
118
|
+
function getResourcesMetadata(target) {
|
|
119
|
+
return Reflect.getMetadata(METADATA_KEYS.RESOURCES, target) ?? [];
|
|
120
|
+
}
|
|
121
|
+
function getPromptsMetadata(target) {
|
|
122
|
+
return Reflect.getMetadata(METADATA_KEYS.PROMPTS, target) ?? [];
|
|
123
|
+
}
|
|
124
|
+
function getParamsMetadata(target) {
|
|
125
|
+
return Reflect.getMetadata(METADATA_KEYS.PARAMS, target) ?? [];
|
|
126
|
+
}
|
|
127
|
+
var McpRuntimeServer = class {
|
|
128
|
+
server;
|
|
129
|
+
instance;
|
|
130
|
+
metadata;
|
|
131
|
+
constructor(target, _options = {}) {
|
|
132
|
+
this.metadata = extractMetadata(target);
|
|
133
|
+
if (!this.metadata.server) {
|
|
134
|
+
throw new Error(`Class ${target.name} is not decorated with @McpServer`);
|
|
135
|
+
}
|
|
136
|
+
this.server = new Server(
|
|
137
|
+
{
|
|
138
|
+
name: this.metadata.server.name,
|
|
139
|
+
version: this.metadata.server.version ?? "1.0.0"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
capabilities: {
|
|
143
|
+
tools: this.metadata.tools.length > 0 ? {} : void 0,
|
|
144
|
+
resources: this.metadata.resources.length > 0 ? {} : void 0,
|
|
145
|
+
prompts: this.metadata.prompts.length > 0 ? {} : void 0
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
this.instance = new target();
|
|
150
|
+
this.setupHandlers();
|
|
151
|
+
}
|
|
152
|
+
setupHandlers() {
|
|
153
|
+
this.setupToolHandlers();
|
|
154
|
+
this.setupResourceHandlers();
|
|
155
|
+
this.setupPromptHandlers();
|
|
156
|
+
}
|
|
157
|
+
setupToolHandlers() {
|
|
158
|
+
const tools = this.metadata.tools;
|
|
159
|
+
if (tools.length === 0) return;
|
|
160
|
+
this.server.setRequestHandler({ method: "tools/list" }, async () => ({
|
|
161
|
+
tools: tools.map((tool) => ({
|
|
162
|
+
name: tool.name,
|
|
163
|
+
description: tool.description,
|
|
164
|
+
inputSchema: tool.inputSchema ?? { type: "object", properties: {} }
|
|
165
|
+
}))
|
|
166
|
+
}));
|
|
167
|
+
this.server.setRequestHandler({ method: "tools/call" }, async (request) => {
|
|
168
|
+
const toolName = request.params.name;
|
|
169
|
+
const tool = tools.find((t) => t.name === toolName);
|
|
170
|
+
if (!tool) {
|
|
171
|
+
throw new Error(`Unknown tool: ${toolName}`);
|
|
172
|
+
}
|
|
173
|
+
const method = this.instance[tool.propertyKey];
|
|
174
|
+
if (typeof method !== "function") {
|
|
175
|
+
throw new Error(`Method ${String(tool.propertyKey)} not found`);
|
|
176
|
+
}
|
|
177
|
+
const args = this.resolveToolArgs(tool.propertyKey, request.params.arguments ?? {});
|
|
178
|
+
const result = await method.apply(this.instance, args);
|
|
179
|
+
return {
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
type: "text",
|
|
183
|
+
text: typeof result === "string" ? result : JSON.stringify(result)
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
setupResourceHandlers() {
|
|
190
|
+
const resources = this.metadata.resources;
|
|
191
|
+
if (resources.length === 0) return;
|
|
192
|
+
this.server.setRequestHandler({ method: "resources/list" }, async () => ({
|
|
193
|
+
resources: resources.map((resource) => ({
|
|
194
|
+
uri: resource.uri,
|
|
195
|
+
name: resource.name,
|
|
196
|
+
description: resource.description,
|
|
197
|
+
mimeType: resource.mimeType
|
|
198
|
+
}))
|
|
199
|
+
}));
|
|
200
|
+
this.server.setRequestHandler({ method: "resources/read" }, async (request) => {
|
|
201
|
+
const uri = request.params.uri;
|
|
202
|
+
for (const resource of resources) {
|
|
203
|
+
const params = this.extractUriParams(resource.uri, uri);
|
|
204
|
+
if (params) {
|
|
205
|
+
const method = this.instance[resource.propertyKey];
|
|
206
|
+
if (typeof method !== "function") {
|
|
207
|
+
throw new Error(`Method ${String(resource.propertyKey)} not found`);
|
|
208
|
+
}
|
|
209
|
+
const args = this.resolveResourceArgs(resource.propertyKey, params);
|
|
210
|
+
return await method.apply(this.instance, args);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
throw new Error(`Resource not found: ${uri}`);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
setupPromptHandlers() {
|
|
217
|
+
const prompts = this.metadata.prompts;
|
|
218
|
+
if (prompts.length === 0) return;
|
|
219
|
+
this.server.setRequestHandler({ method: "prompts/list" }, async () => ({
|
|
220
|
+
prompts: prompts.map((prompt) => ({
|
|
221
|
+
name: prompt.name,
|
|
222
|
+
description: prompt.description,
|
|
223
|
+
arguments: prompt.arguments ?? []
|
|
224
|
+
}))
|
|
225
|
+
}));
|
|
226
|
+
this.server.setRequestHandler({ method: "prompts/get" }, async (request) => {
|
|
227
|
+
const promptName = request.params.name;
|
|
228
|
+
const prompt = prompts.find((p) => p.name === promptName);
|
|
229
|
+
if (!prompt) {
|
|
230
|
+
throw new Error(`Unknown prompt: ${promptName}`);
|
|
231
|
+
}
|
|
232
|
+
const method = this.instance[prompt.propertyKey];
|
|
233
|
+
if (typeof method !== "function") {
|
|
234
|
+
throw new Error(`Method ${String(prompt.propertyKey)} not found`);
|
|
235
|
+
}
|
|
236
|
+
const args = this.resolvePromptArgs(prompt.propertyKey, request.params.arguments ?? {});
|
|
237
|
+
return await method.apply(this.instance, args);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
resolveToolArgs(propertyKey, input) {
|
|
241
|
+
const params = this.metadata.params.filter(
|
|
242
|
+
(p) => p.propertyKey === propertyKey && p.type === "input"
|
|
243
|
+
);
|
|
244
|
+
if (params.length === 0) {
|
|
245
|
+
return [input];
|
|
246
|
+
}
|
|
247
|
+
const args = [];
|
|
248
|
+
for (const param of params) {
|
|
249
|
+
args[param.parameterIndex] = input;
|
|
250
|
+
}
|
|
251
|
+
return args;
|
|
252
|
+
}
|
|
253
|
+
resolveResourceArgs(propertyKey, uriParams) {
|
|
254
|
+
const params = this.metadata.params.filter(
|
|
255
|
+
(p) => p.propertyKey === propertyKey && p.type === "param"
|
|
256
|
+
);
|
|
257
|
+
const args = [];
|
|
258
|
+
for (const param of params) {
|
|
259
|
+
if (param.name) {
|
|
260
|
+
args[param.parameterIndex] = uriParams[param.name];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return args;
|
|
264
|
+
}
|
|
265
|
+
resolvePromptArgs(propertyKey, promptArgs) {
|
|
266
|
+
const params = this.metadata.params.filter(
|
|
267
|
+
(p) => p.propertyKey === propertyKey && p.type === "promptArg"
|
|
268
|
+
);
|
|
269
|
+
const args = [];
|
|
270
|
+
for (const param of params) {
|
|
271
|
+
if (param.name) {
|
|
272
|
+
args[param.parameterIndex] = promptArgs[param.name];
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return args;
|
|
276
|
+
}
|
|
277
|
+
extractUriParams(template, uri) {
|
|
278
|
+
const paramNames = [];
|
|
279
|
+
const regexStr = template.replace(/\{(\w+)\}/g, (_, name) => {
|
|
280
|
+
paramNames.push(name);
|
|
281
|
+
return "([^/]+)";
|
|
282
|
+
});
|
|
283
|
+
const regex = new RegExp(`^${regexStr}$`);
|
|
284
|
+
const match = uri.match(regex);
|
|
285
|
+
if (!match) return null;
|
|
286
|
+
const params = {};
|
|
287
|
+
paramNames.forEach((name, index) => {
|
|
288
|
+
params[name] = match[index + 1] ?? "";
|
|
289
|
+
});
|
|
290
|
+
return params;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Start the MCP server
|
|
294
|
+
*/
|
|
295
|
+
async start() {
|
|
296
|
+
const transport = new StdioServerTransport();
|
|
297
|
+
await this.server.connect(transport);
|
|
298
|
+
console.error(`MCP server '${this.metadata.server?.name}' started on stdio`);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Get the underlying MCP server instance
|
|
302
|
+
*/
|
|
303
|
+
getServer() {
|
|
304
|
+
return this.server;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
async function createMcpServer(target, options) {
|
|
308
|
+
const server = new McpRuntimeServer(target, options);
|
|
309
|
+
await server.start();
|
|
310
|
+
return server;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/index.ts
|
|
314
|
+
var VERSION = "0.1.0";
|
|
315
|
+
|
|
316
|
+
export { McpInput, McpParam, McpPrompt, McpPromptArg, McpResource, McpRuntimeServer, McpServer, McpTool, VERSION, createMcpServer, getMcpServers, getParamsMetadata, getPromptsMetadata, getResourcesMetadata, getServerMetadata, getToolsMetadata, isMcpServer };
|
|
317
|
+
//# sourceMappingURL=index.mjs.map
|
|
318
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/decorators/mcp-server.ts","../src/decorators/mcp-tool.ts","../src/decorators/mcp-resource.ts","../src/decorators/mcp-prompt.ts","../src/decorators/params.ts","../src/metadata/storage.ts","../src/runtime/server.ts","../src/index.ts"],"names":["METADATA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,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AACF;AAKA,eAAsB,eAAA,CACpB,QACA,OAAA,EAC2B;AAC3B,EAAA,MAAM,MAAA,GAAS,IAAI,gBAAA,CAAiB,MAAA,EAAQ,OAAO,CAAA;AACnD,EAAA,MAAM,OAAO,KAAA,EAAM;AACnB,EAAA,OAAO,MAAA;AACT;;;ACjPO,IAAM,OAAA,GAAU","file":"index.mjs","sourcesContent":["import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpServerMetadata } from '@mcp-weave/core';\n\n/**\n * Options for @McpServer decorator\n */\nexport interface McpServerOptions {\n /**\n * Server name\n */\n name: string;\n\n /**\n * Server version (default: '1.0.0')\n */\n version?: string;\n\n /**\n * Server description\n */\n description?: string;\n}\n\n/**\n * Marks a class as an MCP server\n *\n * @example\n * ```typescript\n * @McpServer({ name: 'my-service', version: '1.0.0' })\n * export class MyController {\n * // ...\n * }\n * ```\n */\nexport function McpServer(options: McpServerOptions): ClassDecorator {\n return (target: Function) => {\n const metadata: McpServerMetadata = {\n name: options.name,\n version: options.version ?? '1.0.0',\n description: options.description,\n target,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.SERVER, metadata, target);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpToolMetadata, ToolInputSchema } from '@mcp-weave/core';\n\n/**\n * Options for @McpTool decorator\n */\nexport interface McpToolOptions {\n /**\n * Tool name\n */\n name: string;\n\n /**\n * Tool description\n */\n description: string;\n\n /**\n * Input schema (JSON Schema)\n */\n inputSchema?: ToolInputSchema;\n}\n\n/**\n * Marks a method as an MCP tool\n *\n * @example\n * ```typescript\n * @McpTool({\n * name: 'create_user',\n * description: 'Creates a new user'\n * })\n * async createUser(@McpInput() input: CreateUserDto) {\n * return { success: true };\n * }\n * ```\n */\nexport function McpTool(options: McpToolOptions): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n\n const existingTools: McpToolMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.TOOLS, constructor) ?? [];\n\n const metadata: McpToolMetadata = {\n name: options.name,\n description: options.description,\n inputSchema: options.inputSchema,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.TOOLS, [...existingTools, metadata], constructor);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpResourceMetadata } from '@mcp-weave/core';\n\n/**\n * Options for @McpResource decorator\n */\nexport interface McpResourceOptions {\n /**\n * Resource URI template (e.g., 'user://{userId}')\n */\n uri: string;\n\n /**\n * Resource name\n */\n name: string;\n\n /**\n * Resource description\n */\n description?: string;\n\n /**\n * MIME type (default: 'application/json')\n */\n mimeType?: string;\n}\n\n/**\n * Marks a method as an MCP resource\n *\n * @example\n * ```typescript\n * @McpResource({\n * uri: 'user://{userId}',\n * name: 'User Profile',\n * mimeType: 'application/json'\n * })\n * async getUserProfile(@McpParam('userId') userId: string) {\n * return { contents: [...] };\n * }\n * ```\n */\nexport function McpResource(options: McpResourceOptions): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n\n const existingResources: McpResourceMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.RESOURCES, constructor) ?? [];\n\n const metadata: McpResourceMetadata = {\n uri: options.uri,\n name: options.name,\n description: options.description,\n mimeType: options.mimeType ?? 'application/json',\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.RESOURCES, [...existingResources, metadata], constructor);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpPromptMetadata, PromptArgument } from '@mcp-weave/core';\n\n/**\n * Options for @McpPrompt decorator\n */\nexport interface McpPromptOptions {\n /**\n * Prompt name\n */\n name: string;\n\n /**\n * Prompt description\n */\n description: string;\n\n /**\n * Prompt arguments\n */\n arguments?: PromptArgument[];\n}\n\n/**\n * Marks a method as an MCP prompt\n *\n * @example\n * ```typescript\n * @McpPrompt({\n * name: 'welcome_email',\n * description: 'Generate welcome email for new user'\n * })\n * async generateWelcomeEmail(\n * @McpPromptArg('userName') userName: string\n * ) {\n * return { messages: [...] };\n * }\n * ```\n */\nexport function McpPrompt(options: McpPromptOptions): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n\n const existingPrompts: McpPromptMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.PROMPTS, constructor) ?? [];\n\n const metadata: McpPromptMetadata = {\n name: options.name,\n description: options.description,\n arguments: options.arguments,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.PROMPTS, [...existingPrompts, metadata], constructor);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS } from '@mcp-weave/core';\nimport type { McpParamMetadata } from '@mcp-weave/core';\n\n/**\n * Injects the tool input\n *\n * @example\n * ```typescript\n * @McpTool({ name: 'create_user', description: 'Creates a user' })\n * async createUser(@McpInput() input: CreateUserDto) {\n * // input contains the tool arguments\n * }\n * ```\n */\nexport function McpInput(): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n if (!propertyKey) return;\n\n const constructor = target.constructor;\n const existingParams: McpParamMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.PARAMS, constructor) ?? [];\n\n const metadata: McpParamMetadata = {\n type: 'input',\n parameterIndex,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);\n };\n}\n\n/**\n * Injects a URI parameter from a resource\n *\n * @example\n * ```typescript\n * @McpResource({ uri: 'user://{userId}', name: 'User' })\n * async getUser(@McpParam('userId') userId: string) {\n * // userId is extracted from the URI\n * }\n * ```\n */\nexport function McpParam(name: string): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n if (!propertyKey) return;\n\n const constructor = target.constructor;\n const existingParams: McpParamMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.PARAMS, constructor) ?? [];\n\n const metadata: McpParamMetadata = {\n type: 'param',\n name,\n parameterIndex,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);\n };\n}\n\n/**\n * Injects a prompt argument\n *\n * @example\n * ```typescript\n * @McpPrompt({ name: 'welcome', description: 'Welcome prompt' })\n * async generateWelcome(@McpPromptArg('userName') userName: string) {\n * // userName is the prompt argument\n * }\n * ```\n */\nexport function McpPromptArg(name: string): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n if (!propertyKey) return;\n\n const constructor = target.constructor;\n const existingParams: McpParamMetadata[] =\n Reflect.getMetadata(METADATA_KEYS.PARAMS, constructor) ?? [];\n\n const metadata: McpParamMetadata = {\n type: 'promptArg',\n name,\n parameterIndex,\n propertyKey,\n target: constructor,\n };\n\n Reflect.defineMetadata(METADATA_KEYS.PARAMS, [...existingParams, metadata], constructor);\n };\n}\n","import 'reflect-metadata';\nimport { METADATA_KEYS, extractMetadata, type ScannedMetadata } from '@mcp-weave/core';\nimport type {\n McpServerMetadata,\n McpToolMetadata,\n McpResourceMetadata,\n McpPromptMetadata,\n McpParamMetadata,\n} from '@mcp-weave/core';\n\n// Re-export for convenience\nexport { METADATA_KEYS, extractMetadata };\nexport type {\n ScannedMetadata,\n McpServerMetadata,\n McpToolMetadata,\n McpResourceMetadata,\n McpPromptMetadata,\n McpParamMetadata,\n};\n\n/**\n * Check if a class has @McpServer decorator\n */\nexport function isMcpServer(target: Function): boolean {\n return Reflect.hasMetadata(METADATA_KEYS.SERVER, target);\n}\n\n/**\n * Get all MCP servers from an array of classes\n */\nexport function getMcpServers(targets: Function[]): Function[] {\n return targets.filter(isMcpServer);\n}\n\n/**\n * Get server metadata from a class\n */\nexport function getServerMetadata(target: Function): McpServerMetadata | undefined {\n return Reflect.getMetadata(METADATA_KEYS.SERVER, target);\n}\n\n/**\n * Get tools metadata from a class\n */\nexport function getToolsMetadata(target: Function): McpToolMetadata[] {\n return Reflect.getMetadata(METADATA_KEYS.TOOLS, target) ?? [];\n}\n\n/**\n * Get resources metadata from a class\n */\nexport function getResourcesMetadata(target: Function): McpResourceMetadata[] {\n return Reflect.getMetadata(METADATA_KEYS.RESOURCES, target) ?? [];\n}\n\n/**\n * Get prompts metadata from a class\n */\nexport function getPromptsMetadata(target: Function): McpPromptMetadata[] {\n return Reflect.getMetadata(METADATA_KEYS.PROMPTS, target) ?? [];\n}\n\n/**\n * Get params metadata from a class\n */\nexport function getParamsMetadata(target: Function): McpParamMetadata[] {\n return Reflect.getMetadata(METADATA_KEYS.PARAMS, target) ?? [];\n}\n","import { Server } from '@modelcontextprotocol/sdk/server/index.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\n\nimport { extractMetadata } from '../metadata/storage.js';\n\n/**\n * Options for MCP runtime server\n */\nexport interface McpRuntimeOptions {\n /**\n * Transport type\n */\n transport?: 'stdio' | 'sse';\n}\n\n/**\n * Runtime MCP server that wraps a decorated class\n */\nexport class McpRuntimeServer {\n private server: Server;\n private instance: any;\n private metadata;\n\n constructor(target: Function, _options: McpRuntimeOptions = {}) {\n this.metadata = extractMetadata(target);\n\n if (!this.metadata.server) {\n throw new Error(`Class ${target.name} is not decorated with @McpServer`);\n }\n\n this.server = new Server(\n {\n name: this.metadata.server.name,\n version: this.metadata.server.version ?? '1.0.0',\n },\n {\n capabilities: {\n tools: this.metadata.tools.length > 0 ? {} : undefined,\n resources: this.metadata.resources.length > 0 ? {} : undefined,\n prompts: this.metadata.prompts.length > 0 ? {} : undefined,\n },\n }\n );\n\n // Create instance of the target class\n this.instance = new (target as any)();\n\n this.setupHandlers();\n }\n\n private setupHandlers() {\n this.setupToolHandlers();\n this.setupResourceHandlers();\n this.setupPromptHandlers();\n }\n\n private setupToolHandlers() {\n const tools = this.metadata.tools;\n if (tools.length === 0) return;\n\n // List tools\n this.server.setRequestHandler({ method: 'tools/list' } as any, async () => ({\n tools: tools.map(tool => ({\n name: tool.name,\n description: tool.description,\n inputSchema: tool.inputSchema ?? { type: 'object' as const, properties: {} },\n })),\n }));\n\n // Call tool\n this.server.setRequestHandler({ method: 'tools/call' } as any, async (request: any) => {\n const toolName = request.params.name;\n const tool = tools.find(t => t.name === toolName);\n\n if (!tool) {\n throw new Error(`Unknown tool: ${toolName}`);\n }\n\n const method = this.instance[tool.propertyKey];\n if (typeof method !== 'function') {\n throw new Error(`Method ${String(tool.propertyKey)} not found`);\n }\n\n const args = this.resolveToolArgs(tool.propertyKey, request.params.arguments ?? {});\n const result = await method.apply(this.instance, args);\n\n return {\n content: [\n {\n type: 'text',\n text: typeof result === 'string' ? result : JSON.stringify(result),\n },\n ],\n };\n });\n }\n\n private setupResourceHandlers() {\n const resources = this.metadata.resources;\n if (resources.length === 0) return;\n\n // List resources\n this.server.setRequestHandler({ method: 'resources/list' } as any, async () => ({\n resources: resources.map(resource => ({\n uri: resource.uri,\n name: resource.name,\n description: resource.description,\n mimeType: resource.mimeType,\n })),\n }));\n\n // Read resource\n this.server.setRequestHandler({ method: 'resources/read' } as any, async (request: any) => {\n const uri = request.params.uri as string;\n\n // Find matching resource\n for (const resource of resources) {\n const params = this.extractUriParams(resource.uri, uri);\n if (params) {\n const method = this.instance[resource.propertyKey];\n if (typeof method !== 'function') {\n throw new Error(`Method ${String(resource.propertyKey)} not found`);\n }\n\n const args = this.resolveResourceArgs(resource.propertyKey, params);\n return await method.apply(this.instance, args);\n }\n }\n\n throw new Error(`Resource not found: ${uri}`);\n });\n }\n\n private setupPromptHandlers() {\n const prompts = this.metadata.prompts;\n if (prompts.length === 0) return;\n\n // List prompts\n this.server.setRequestHandler({ method: 'prompts/list' } as any, async () => ({\n prompts: prompts.map(prompt => ({\n name: prompt.name,\n description: prompt.description,\n arguments: prompt.arguments ?? [],\n })),\n }));\n\n // Get prompt\n this.server.setRequestHandler({ method: 'prompts/get' } as any, async (request: any) => {\n const promptName = request.params.name;\n const prompt = prompts.find(p => p.name === promptName);\n\n if (!prompt) {\n throw new Error(`Unknown prompt: ${promptName}`);\n }\n\n const method = this.instance[prompt.propertyKey];\n if (typeof method !== 'function') {\n throw new Error(`Method ${String(prompt.propertyKey)} not found`);\n }\n\n const args = this.resolvePromptArgs(prompt.propertyKey, request.params.arguments ?? {});\n return await method.apply(this.instance, args);\n });\n }\n\n private resolveToolArgs(propertyKey: string | symbol, input: Record<string, any>): any[] {\n const params = this.metadata.params.filter(\n p => p.propertyKey === propertyKey && p.type === 'input'\n );\n\n if (params.length === 0) {\n return [input];\n }\n\n const args: any[] = [];\n for (const param of params) {\n args[param.parameterIndex] = input;\n }\n return args;\n }\n\n private resolveResourceArgs(\n propertyKey: string | symbol,\n uriParams: Record<string, string>\n ): any[] {\n const params = this.metadata.params.filter(\n p => p.propertyKey === propertyKey && p.type === 'param'\n );\n\n const args: any[] = [];\n for (const param of params) {\n if (param.name) {\n args[param.parameterIndex] = uriParams[param.name];\n }\n }\n return args;\n }\n\n private resolvePromptArgs(propertyKey: string | symbol, promptArgs: Record<string, any>): any[] {\n const params = this.metadata.params.filter(\n p => p.propertyKey === propertyKey && p.type === 'promptArg'\n );\n\n const args: any[] = [];\n for (const param of params) {\n if (param.name) {\n args[param.parameterIndex] = promptArgs[param.name];\n }\n }\n return args;\n }\n\n private extractUriParams(template: string, uri: string): Record<string, string> | null {\n // Convert template to regex: user://{userId} -> user://([^/]+)\n const paramNames: string[] = [];\n const regexStr = template.replace(/\\{(\\w+)\\}/g, (_, name) => {\n paramNames.push(name);\n return '([^/]+)';\n });\n\n const regex = new RegExp(`^${regexStr}$`);\n const match = uri.match(regex);\n\n if (!match) return null;\n\n const params: Record<string, string> = {};\n paramNames.forEach((name, index) => {\n params[name] = match[index + 1] ?? '';\n });\n\n return params;\n }\n\n /**\n * Start the MCP server\n */\n async start(): Promise<void> {\n const transport = new StdioServerTransport();\n await this.server.connect(transport);\n console.error(`MCP server '${this.metadata.server?.name}' started on stdio`);\n }\n\n /**\n * Get the underlying MCP server instance\n */\n getServer(): Server {\n return this.server;\n }\n}\n\n/**\n * Create and start an MCP server from a decorated class\n */\nexport async function createMcpServer(\n target: Function,\n options?: McpRuntimeOptions\n): Promise<McpRuntimeServer> {\n const server = new McpRuntimeServer(target, options);\n await server.start();\n return server;\n}\n","// @mcp-weave/nestjs\n// NestJS integration for MCP-Weave\n\nimport 'reflect-metadata';\n\n// Decorators\nexport * from './decorators/mcp-server.js';\nexport * from './decorators/mcp-tool.js';\nexport * from './decorators/mcp-resource.js';\nexport * from './decorators/mcp-prompt.js';\nexport * from './decorators/params.js';\n\n// Metadata\nexport * from './metadata/storage.js';\n\n// Runtime\nexport * from './runtime/server.js';\n\n// Version\nexport const VERSION = '0.1.0';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcp-weave/nestjs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "NestJS integration for MCP-Weave - decorators and runtime",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
20
|
+
"reflect-metadata": "^0.2.0",
|
|
21
|
+
"@mcp-weave/core": "0.1.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@nestjs/common": "^10.3.0",
|
|
25
|
+
"@nestjs/core": "^10.3.0",
|
|
26
|
+
"@types/node": "^20.11.0",
|
|
27
|
+
"rimraf": "^5.0.0",
|
|
28
|
+
"rxjs": "^7.8.0",
|
|
29
|
+
"tsup": "^8.0.0",
|
|
30
|
+
"typescript": "^5.4.0",
|
|
31
|
+
"vitest": "^1.3.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@nestjs/common": "^10.0.0",
|
|
35
|
+
"@nestjs/core": "^10.0.0",
|
|
36
|
+
"rxjs": "^7.0.0"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"mcp",
|
|
40
|
+
"nestjs",
|
|
41
|
+
"decorators",
|
|
42
|
+
"model-context-protocol"
|
|
43
|
+
],
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/mcp-weave/mcp-weave.git",
|
|
47
|
+
"directory": "packages/nestjs"
|
|
48
|
+
},
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"dev": "tsup --watch",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"test:watch": "vitest",
|
|
58
|
+
"test:coverage": "vitest run --coverage",
|
|
59
|
+
"lint": "eslint src --ext .ts",
|
|
60
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"clean": "rimraf dist coverage"
|
|
63
|
+
}
|
|
64
|
+
}
|