@riktajs/mcp 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/README.md +399 -0
- package/dist/constants.d.ts +23 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +23 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators/index.d.ts +9 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +12 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/mcp-prompt.decorator.d.ts +52 -0
- package/dist/decorators/mcp-prompt.decorator.d.ts.map +1 -0
- package/dist/decorators/mcp-prompt.decorator.js +64 -0
- package/dist/decorators/mcp-prompt.decorator.js.map +1 -0
- package/dist/decorators/mcp-resource.decorator.d.ts +49 -0
- package/dist/decorators/mcp-resource.decorator.d.ts.map +1 -0
- package/dist/decorators/mcp-resource.decorator.js +66 -0
- package/dist/decorators/mcp-resource.decorator.js.map +1 -0
- package/dist/decorators/mcp-tool.decorator.d.ts +45 -0
- package/dist/decorators/mcp-tool.decorator.d.ts.map +1 -0
- package/dist/decorators/mcp-tool.decorator.js +57 -0
- package/dist/decorators/mcp-tool.decorator.js.map +1 -0
- package/dist/discovery/index.d.ts +7 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/discovery/index.js +7 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/mcp-registry.d.ts +80 -0
- package/dist/discovery/mcp-registry.d.ts.map +1 -0
- package/dist/discovery/mcp-registry.js +179 -0
- package/dist/discovery/mcp-registry.js.map +1 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +81 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/index.d.ts +7 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +7 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/mcp.plugin.d.ts +72 -0
- package/dist/plugin/mcp.plugin.d.ts.map +1 -0
- package/dist/plugin/mcp.plugin.js +198 -0
- package/dist/plugin/mcp.plugin.js.map +1 -0
- package/dist/types.d.ts +337 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/zod-to-schema.d.ts +48 -0
- package/dist/utils/zod-to-schema.d.ts.map +1 -0
- package/dist/utils/zod-to-schema.js +67 -0
- package/dist/utils/zod-to-schema.js.map +1 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
# @riktajs/mcp
|
|
2
|
+
|
|
3
|
+
Model Context Protocol (MCP) integration for Rikta Framework. Connect AI assistants like Claude and GPT to your Rikta backend with decorator-based APIs.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🤖 **Decorator-based API** - Define MCP tools, resources, and prompts with `@MCPTool`, `@MCPResource`, `@MCPPrompt`
|
|
8
|
+
- 🔍 **Auto-discovery** - Automatically discovers MCP handlers from `@Injectable` classes
|
|
9
|
+
- 📝 **Zod Integration** - Full Zod support for input schema validation (consistent with Rikta ecosystem)
|
|
10
|
+
- 📡 **SSE Support** - Server-Sent Events for real-time notifications
|
|
11
|
+
- 🔄 **Horizontal Scaling** - Redis support for multi-instance deployments
|
|
12
|
+
- 🔒 **Type Safe** - Complete TypeScript definitions
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @riktajs/mcp zod
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
> **Note**: `@platformatic/mcp` is included as a dependency and will be installed automatically.
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { Rikta, Injectable } from '@riktajs/core';
|
|
26
|
+
import { registerMCPServer, MCPTool, MCPResource, z } from '@riktajs/mcp';
|
|
27
|
+
import { promises as fs } from 'fs';
|
|
28
|
+
|
|
29
|
+
@Injectable()
|
|
30
|
+
class FileService {
|
|
31
|
+
@MCPTool({
|
|
32
|
+
name: 'list_files',
|
|
33
|
+
description: 'List files in a directory',
|
|
34
|
+
inputSchema: z.object({
|
|
35
|
+
path: z.string().describe('Directory path to list'),
|
|
36
|
+
showHidden: z.boolean().optional().default(false),
|
|
37
|
+
}),
|
|
38
|
+
})
|
|
39
|
+
async listFiles(params: { path: string; showHidden?: boolean }) {
|
|
40
|
+
const files = await fs.readdir(params.path);
|
|
41
|
+
const filtered = params.showHidden
|
|
42
|
+
? files
|
|
43
|
+
: files.filter(f => !f.startsWith('.'));
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
content: [{
|
|
47
|
+
type: 'text',
|
|
48
|
+
text: filtered.join('\n'),
|
|
49
|
+
}],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@MCPResource({
|
|
54
|
+
uriPattern: 'file://read',
|
|
55
|
+
name: 'Read File',
|
|
56
|
+
description: 'Read file contents by path',
|
|
57
|
+
mimeType: 'text/plain',
|
|
58
|
+
})
|
|
59
|
+
async readFile(uri: string) {
|
|
60
|
+
const url = new URL(uri);
|
|
61
|
+
const filePath = url.searchParams.get('path')!;
|
|
62
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
contents: [{
|
|
66
|
+
uri,
|
|
67
|
+
text: content,
|
|
68
|
+
mimeType: 'text/plain',
|
|
69
|
+
}],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Bootstrap application
|
|
75
|
+
const app = await Rikta.create({ port: 3000 });
|
|
76
|
+
|
|
77
|
+
// Register MCP server
|
|
78
|
+
await registerMCPServer(app, {
|
|
79
|
+
serverInfo: { name: 'file-server', version: '1.0.0' },
|
|
80
|
+
instructions: 'A file system server for reading and listing files',
|
|
81
|
+
enableSSE: true,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await app.listen();
|
|
85
|
+
// MCP available at http://localhost:3000/mcp
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Decorators
|
|
89
|
+
|
|
90
|
+
### @MCPTool
|
|
91
|
+
|
|
92
|
+
Marks a method as an MCP tool that AI assistants can invoke.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
@Injectable()
|
|
96
|
+
class CalculatorService {
|
|
97
|
+
@MCPTool({
|
|
98
|
+
name: 'calculate',
|
|
99
|
+
description: 'Perform a calculation',
|
|
100
|
+
inputSchema: z.object({
|
|
101
|
+
operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
|
|
102
|
+
a: z.number(),
|
|
103
|
+
b: z.number(),
|
|
104
|
+
}),
|
|
105
|
+
})
|
|
106
|
+
async calculate(params: { operation: string; a: number; b: number }) {
|
|
107
|
+
let result: number;
|
|
108
|
+
switch (params.operation) {
|
|
109
|
+
case 'add': result = params.a + params.b; break;
|
|
110
|
+
case 'subtract': result = params.a - params.b; break;
|
|
111
|
+
case 'multiply': result = params.a * params.b; break;
|
|
112
|
+
case 'divide': result = params.a / params.b; break;
|
|
113
|
+
default: throw new Error('Unknown operation');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
content: [{ type: 'text', text: `Result: ${result}` }],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### @MCPResource
|
|
124
|
+
|
|
125
|
+
Marks a method as an MCP resource provider.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
@Injectable()
|
|
129
|
+
class DatabaseService {
|
|
130
|
+
@MCPResource({
|
|
131
|
+
uriPattern: 'db://users',
|
|
132
|
+
name: 'Users Database',
|
|
133
|
+
description: 'Query users from the database',
|
|
134
|
+
mimeType: 'application/json',
|
|
135
|
+
})
|
|
136
|
+
async getUsers(uri: string) {
|
|
137
|
+
const url = new URL(uri);
|
|
138
|
+
const limit = parseInt(url.searchParams.get('limit') || '10');
|
|
139
|
+
|
|
140
|
+
const users = await this.userRepository.find({ take: limit });
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
contents: [{
|
|
144
|
+
uri,
|
|
145
|
+
text: JSON.stringify(users, null, 2),
|
|
146
|
+
mimeType: 'application/json',
|
|
147
|
+
}],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### @MCPPrompt
|
|
154
|
+
|
|
155
|
+
Marks a method as an MCP prompt template.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
@Injectable()
|
|
159
|
+
class PromptService {
|
|
160
|
+
@MCPPrompt({
|
|
161
|
+
name: 'code_review',
|
|
162
|
+
description: 'Generate a code review prompt',
|
|
163
|
+
arguments: [
|
|
164
|
+
{ name: 'language', description: 'Programming language', required: true },
|
|
165
|
+
{ name: 'code', description: 'Code to review', required: true },
|
|
166
|
+
{ name: 'focus', description: 'Specific areas to focus on' },
|
|
167
|
+
],
|
|
168
|
+
})
|
|
169
|
+
async codeReview(args: { language: string; code: string; focus?: string }) {
|
|
170
|
+
const focusArea = args.focus ? `\nFocus on: ${args.focus}` : '';
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
messages: [
|
|
174
|
+
{
|
|
175
|
+
role: 'user',
|
|
176
|
+
content: {
|
|
177
|
+
type: 'text',
|
|
178
|
+
text: `Please review this ${args.language} code:${focusArea}\n\n\`\`\`${args.language}\n${args.code}\n\`\`\``,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Zod Schema Examples
|
|
188
|
+
|
|
189
|
+
The package uses Zod for schema validation, consistent with the rest of the Rikta ecosystem:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { z } from '@riktajs/mcp'; // Re-exported for convenience
|
|
193
|
+
|
|
194
|
+
// Simple string with description
|
|
195
|
+
const pathSchema = z.string().describe('File path to read');
|
|
196
|
+
|
|
197
|
+
// Object with optional fields
|
|
198
|
+
const optionsSchema = z.object({
|
|
199
|
+
path: z.string().describe('Directory path'),
|
|
200
|
+
recursive: z.boolean().optional().default(false),
|
|
201
|
+
maxDepth: z.number().min(1).max(10).optional(),
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Enum for fixed values
|
|
205
|
+
const operationSchema = z.enum(['read', 'write', 'delete']);
|
|
206
|
+
|
|
207
|
+
// Array of objects
|
|
208
|
+
const filesSchema = z.array(z.object({
|
|
209
|
+
name: z.string(),
|
|
210
|
+
size: z.number(),
|
|
211
|
+
}));
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Configuration
|
|
215
|
+
|
|
216
|
+
### Basic Configuration
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
await registerMCPServer(app, {
|
|
220
|
+
serverInfo: {
|
|
221
|
+
name: 'my-mcp-server',
|
|
222
|
+
version: '1.0.0',
|
|
223
|
+
},
|
|
224
|
+
instructions: 'Instructions for AI assistants on how to use this server',
|
|
225
|
+
enableSSE: true,
|
|
226
|
+
path: '/mcp', // Custom endpoint path
|
|
227
|
+
});
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Redis Configuration (Horizontal Scaling)
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
await registerMCPServer(app, {
|
|
234
|
+
serverInfo: { name: 'scaled-server', version: '1.0.0' },
|
|
235
|
+
redis: {
|
|
236
|
+
host: 'localhost',
|
|
237
|
+
port: 6379,
|
|
238
|
+
password: 'your-password', // optional
|
|
239
|
+
db: 0, // optional
|
|
240
|
+
},
|
|
241
|
+
sessionTTL: 3600, // Session TTL in seconds
|
|
242
|
+
});
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Full Configuration Options
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
interface MCPServerOptions {
|
|
249
|
+
// Server identification
|
|
250
|
+
serverInfo?: { name: string; version: string };
|
|
251
|
+
|
|
252
|
+
// Instructions for AI assistants
|
|
253
|
+
instructions?: string;
|
|
254
|
+
|
|
255
|
+
// Enable SSE (Server-Sent Events)
|
|
256
|
+
enableSSE?: boolean; // default: true
|
|
257
|
+
|
|
258
|
+
// Custom endpoint path
|
|
259
|
+
path?: string; // default: '/mcp'
|
|
260
|
+
|
|
261
|
+
// Redis for horizontal scaling
|
|
262
|
+
redis?: {
|
|
263
|
+
host: string;
|
|
264
|
+
port?: number; // default: 6379
|
|
265
|
+
password?: string;
|
|
266
|
+
db?: number; // default: 0
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// Session configuration
|
|
270
|
+
sessionTTL?: number; // default: 3600
|
|
271
|
+
|
|
272
|
+
// Heartbeat configuration
|
|
273
|
+
heartbeat?: boolean; // default: true
|
|
274
|
+
heartbeatInterval?: number; // default: 30000ms
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Endpoints
|
|
279
|
+
|
|
280
|
+
After registering the MCP server, the following endpoints are available:
|
|
281
|
+
|
|
282
|
+
| Method | Path | Description |
|
|
283
|
+
|--------|------|-------------|
|
|
284
|
+
| POST | `/mcp` | JSON-RPC endpoint for MCP requests |
|
|
285
|
+
| GET | `/mcp` | SSE endpoint for real-time notifications |
|
|
286
|
+
|
|
287
|
+
## Testing with MCP Inspector
|
|
288
|
+
|
|
289
|
+
You can test your MCP server using the official MCP Inspector:
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
# Start your server
|
|
293
|
+
npm run dev
|
|
294
|
+
|
|
295
|
+
# In another terminal, run the inspector
|
|
296
|
+
npx @modelcontextprotocol/inspector http://localhost:3000/mcp
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Testing with curl
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
# Initialize connection
|
|
303
|
+
curl -X POST http://localhost:3000/mcp \
|
|
304
|
+
-H "Content-Type: application/json" \
|
|
305
|
+
-d '{
|
|
306
|
+
"jsonrpc": "2.0",
|
|
307
|
+
"id": 1,
|
|
308
|
+
"method": "initialize",
|
|
309
|
+
"params": {
|
|
310
|
+
"protocolVersion": "2024-11-05",
|
|
311
|
+
"clientInfo": { "name": "test", "version": "1.0.0" },
|
|
312
|
+
"capabilities": {}
|
|
313
|
+
}
|
|
314
|
+
}'
|
|
315
|
+
|
|
316
|
+
# Call a tool
|
|
317
|
+
curl -X POST http://localhost:3000/mcp \
|
|
318
|
+
-H "Content-Type: application/json" \
|
|
319
|
+
-d '{
|
|
320
|
+
"jsonrpc": "2.0",
|
|
321
|
+
"id": 2,
|
|
322
|
+
"method": "tools/call",
|
|
323
|
+
"params": {
|
|
324
|
+
"name": "list_files",
|
|
325
|
+
"arguments": { "path": "." }
|
|
326
|
+
}
|
|
327
|
+
}'
|
|
328
|
+
|
|
329
|
+
# Read a resource
|
|
330
|
+
curl -X POST http://localhost:3000/mcp \
|
|
331
|
+
-H "Content-Type: application/json" \
|
|
332
|
+
-d '{
|
|
333
|
+
"jsonrpc": "2.0",
|
|
334
|
+
"id": 3,
|
|
335
|
+
"method": "resources/read",
|
|
336
|
+
"params": {
|
|
337
|
+
"uri": "file://read?path=package.json"
|
|
338
|
+
}
|
|
339
|
+
}'
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## API Reference
|
|
343
|
+
|
|
344
|
+
### registerMCPServer
|
|
345
|
+
|
|
346
|
+
Main function to register MCP server with a Rikta application.
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
async function registerMCPServer(
|
|
350
|
+
app: RiktaApplication,
|
|
351
|
+
options?: MCPServerOptions
|
|
352
|
+
): Promise<void>
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### mcpRegistry
|
|
356
|
+
|
|
357
|
+
Access the MCP registry for advanced use cases.
|
|
358
|
+
|
|
359
|
+
```typescript
|
|
360
|
+
import { mcpRegistry } from '@riktajs/mcp';
|
|
361
|
+
|
|
362
|
+
// Get all registered handlers
|
|
363
|
+
const tools = mcpRegistry.getTools();
|
|
364
|
+
const resources = mcpRegistry.getResources();
|
|
365
|
+
const prompts = mcpRegistry.getPrompts();
|
|
366
|
+
|
|
367
|
+
// Get stats
|
|
368
|
+
const stats = mcpRegistry.getStats();
|
|
369
|
+
// { tools: 5, resources: 2, prompts: 3 }
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Zod Re-exports
|
|
373
|
+
|
|
374
|
+
For convenience, `z` from Zod is re-exported from this package:
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
import { z } from '@riktajs/mcp';
|
|
378
|
+
|
|
379
|
+
const schema = z.object({
|
|
380
|
+
name: z.string(),
|
|
381
|
+
age: z.number(),
|
|
382
|
+
});
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Utility Functions
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
import { zodToMCPSchema, isZodSchema } from '@riktajs/mcp';
|
|
389
|
+
|
|
390
|
+
// Check if a value is a Zod schema
|
|
391
|
+
if (isZodSchema(schema)) {
|
|
392
|
+
// Convert to JSON Schema for MCP
|
|
393
|
+
const jsonSchema = zodToMCPSchema(schema);
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
## License
|
|
398
|
+
|
|
399
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @riktajs/mcp - Constants
|
|
3
|
+
*
|
|
4
|
+
* Metadata keys for MCP decorators using Symbol.for() for cross-package sharing.
|
|
5
|
+
*/
|
|
6
|
+
/** Metadata key for @MCPTool decorator */
|
|
7
|
+
export declare const MCP_TOOL_METADATA: unique symbol;
|
|
8
|
+
/** Metadata key for @MCPResource decorator */
|
|
9
|
+
export declare const MCP_RESOURCE_METADATA: unique symbol;
|
|
10
|
+
/** Metadata key for @MCPPrompt decorator */
|
|
11
|
+
export declare const MCP_PROMPT_METADATA: unique symbol;
|
|
12
|
+
/** Metadata key for storing all MCP handler methods on a class */
|
|
13
|
+
export declare const MCP_HANDLERS_METADATA: unique symbol;
|
|
14
|
+
/** Metadata key to mark a class as an MCP service */
|
|
15
|
+
export declare const MCP_SERVICE_METADATA: unique symbol;
|
|
16
|
+
/** Default MCP endpoint path */
|
|
17
|
+
export declare const DEFAULT_MCP_PATH = "/mcp";
|
|
18
|
+
/** Default server info */
|
|
19
|
+
export declare const DEFAULT_SERVER_INFO: {
|
|
20
|
+
readonly name: "rikta-mcp-server";
|
|
21
|
+
readonly version: "1.0.0";
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,0CAA0C;AAC1C,eAAO,MAAM,iBAAiB,eAA+B,CAAC;AAE9D,8CAA8C;AAC9C,eAAO,MAAM,qBAAqB,eAAmC,CAAC;AAEtE,4CAA4C;AAC5C,eAAO,MAAM,mBAAmB,eAAiC,CAAC;AAElE,kEAAkE;AAClE,eAAO,MAAM,qBAAqB,eAAmC,CAAC;AAEtE,qDAAqD;AACrD,eAAO,MAAM,oBAAoB,eAAkC,CAAC;AAEpE,gCAAgC;AAChC,eAAO,MAAM,gBAAgB,SAAS,CAAC;AAEvC,0BAA0B;AAC1B,eAAO,MAAM,mBAAmB;;;CAGtB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @riktajs/mcp - Constants
|
|
3
|
+
*
|
|
4
|
+
* Metadata keys for MCP decorators using Symbol.for() for cross-package sharing.
|
|
5
|
+
*/
|
|
6
|
+
/** Metadata key for @MCPTool decorator */
|
|
7
|
+
export const MCP_TOOL_METADATA = Symbol.for('rikta:mcp:tool');
|
|
8
|
+
/** Metadata key for @MCPResource decorator */
|
|
9
|
+
export const MCP_RESOURCE_METADATA = Symbol.for('rikta:mcp:resource');
|
|
10
|
+
/** Metadata key for @MCPPrompt decorator */
|
|
11
|
+
export const MCP_PROMPT_METADATA = Symbol.for('rikta:mcp:prompt');
|
|
12
|
+
/** Metadata key for storing all MCP handler methods on a class */
|
|
13
|
+
export const MCP_HANDLERS_METADATA = Symbol.for('rikta:mcp:handlers');
|
|
14
|
+
/** Metadata key to mark a class as an MCP service */
|
|
15
|
+
export const MCP_SERVICE_METADATA = Symbol.for('rikta:mcp:service');
|
|
16
|
+
/** Default MCP endpoint path */
|
|
17
|
+
export const DEFAULT_MCP_PATH = '/mcp';
|
|
18
|
+
/** Default server info */
|
|
19
|
+
export const DEFAULT_SERVER_INFO = {
|
|
20
|
+
name: 'rikta-mcp-server',
|
|
21
|
+
version: '1.0.0',
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,0CAA0C;AAC1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAE9D,8CAA8C;AAC9C,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAEtE,4CAA4C;AAC5C,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAElE,kEAAkE;AAClE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAEtE,qDAAqD;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAEpE,gCAAgC;AAChC,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEvC,0BAA0B;AAC1B,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,OAAO;CACR,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @riktajs/mcp - Decorators
|
|
3
|
+
*
|
|
4
|
+
* Export all MCP decorators from a single entry point.
|
|
5
|
+
*/
|
|
6
|
+
export { MCPTool, getMCPToolMetadata } from './mcp-tool.decorator.js';
|
|
7
|
+
export { MCPResource, getMCPResourceMetadata } from './mcp-resource.decorator.js';
|
|
8
|
+
export { MCPPrompt, getMCPPromptMetadata } from './mcp-prompt.decorator.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGtE,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGlF,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @riktajs/mcp - Decorators
|
|
3
|
+
*
|
|
4
|
+
* Export all MCP decorators from a single entry point.
|
|
5
|
+
*/
|
|
6
|
+
// Tool decorator
|
|
7
|
+
export { MCPTool, getMCPToolMetadata } from './mcp-tool.decorator.js';
|
|
8
|
+
// Resource decorator
|
|
9
|
+
export { MCPResource, getMCPResourceMetadata } from './mcp-resource.decorator.js';
|
|
10
|
+
// Prompt decorator
|
|
11
|
+
export { MCPPrompt, getMCPPromptMetadata } from './mcp-prompt.decorator.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,iBAAiB;AACjB,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAEtE,qBAAqB;AACrB,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAElF,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @MCPPrompt Decorator
|
|
3
|
+
*
|
|
4
|
+
* Marks a method as an MCP prompt template.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Injectable } from '@riktajs/core';
|
|
9
|
+
* import { MCPPrompt } from '@riktajs/mcp';
|
|
10
|
+
*
|
|
11
|
+
* @Injectable()
|
|
12
|
+
* class PromptService {
|
|
13
|
+
* @MCPPrompt({
|
|
14
|
+
* name: 'code_review',
|
|
15
|
+
* description: 'Generate a code review prompt',
|
|
16
|
+
* arguments: [
|
|
17
|
+
* { name: 'language', description: 'Programming language', required: true },
|
|
18
|
+
* { name: 'code', description: 'Code to review', required: true }
|
|
19
|
+
* ]
|
|
20
|
+
* })
|
|
21
|
+
* async codeReview(args: { language: string; code: string }) {
|
|
22
|
+
* return {
|
|
23
|
+
* messages: [
|
|
24
|
+
* {
|
|
25
|
+
* role: 'user',
|
|
26
|
+
* content: {
|
|
27
|
+
* type: 'text',
|
|
28
|
+
* text: `Please review this ${args.language} code:\n\n${args.code}`
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ]
|
|
32
|
+
* };
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
import 'reflect-metadata';
|
|
38
|
+
import type { MCPPromptOptions } from '../types.js';
|
|
39
|
+
/**
|
|
40
|
+
* @MCPPrompt() decorator
|
|
41
|
+
*
|
|
42
|
+
* Registers a method as an MCP prompt template.
|
|
43
|
+
*
|
|
44
|
+
* @param options - Prompt configuration options
|
|
45
|
+
*/
|
|
46
|
+
export declare function MCPPrompt(options: MCPPromptOptions): MethodDecorator;
|
|
47
|
+
/**
|
|
48
|
+
* Get prompt metadata from a method
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export declare function getMCPPromptMetadata(target: Function, propertyKey: string | symbol): MCPPromptOptions | undefined;
|
|
52
|
+
//# sourceMappingURL=mcp-prompt.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-prompt.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/mcp-prompt.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAkBpE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,QAAQ,EAChB,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,gBAAgB,GAAG,SAAS,CAE9B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @MCPPrompt Decorator
|
|
3
|
+
*
|
|
4
|
+
* Marks a method as an MCP prompt template.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Injectable } from '@riktajs/core';
|
|
9
|
+
* import { MCPPrompt } from '@riktajs/mcp';
|
|
10
|
+
*
|
|
11
|
+
* @Injectable()
|
|
12
|
+
* class PromptService {
|
|
13
|
+
* @MCPPrompt({
|
|
14
|
+
* name: 'code_review',
|
|
15
|
+
* description: 'Generate a code review prompt',
|
|
16
|
+
* arguments: [
|
|
17
|
+
* { name: 'language', description: 'Programming language', required: true },
|
|
18
|
+
* { name: 'code', description: 'Code to review', required: true }
|
|
19
|
+
* ]
|
|
20
|
+
* })
|
|
21
|
+
* async codeReview(args: { language: string; code: string }) {
|
|
22
|
+
* return {
|
|
23
|
+
* messages: [
|
|
24
|
+
* {
|
|
25
|
+
* role: 'user',
|
|
26
|
+
* content: {
|
|
27
|
+
* type: 'text',
|
|
28
|
+
* text: `Please review this ${args.language} code:\n\n${args.code}`
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ]
|
|
32
|
+
* };
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
import 'reflect-metadata';
|
|
38
|
+
import { MCP_PROMPT_METADATA, MCP_HANDLERS_METADATA } from '../constants.js';
|
|
39
|
+
/**
|
|
40
|
+
* @MCPPrompt() decorator
|
|
41
|
+
*
|
|
42
|
+
* Registers a method as an MCP prompt template.
|
|
43
|
+
*
|
|
44
|
+
* @param options - Prompt configuration options
|
|
45
|
+
*/
|
|
46
|
+
export function MCPPrompt(options) {
|
|
47
|
+
return (target, propertyKey, descriptor) => {
|
|
48
|
+
// Store prompt metadata on the method
|
|
49
|
+
Reflect.defineMetadata(MCP_PROMPT_METADATA, options, target, propertyKey);
|
|
50
|
+
// Add to the class's list of MCP handlers
|
|
51
|
+
const handlers = Reflect.getMetadata(MCP_HANDLERS_METADATA, target.constructor) || [];
|
|
52
|
+
handlers.push({ type: 'prompt', methodName: propertyKey });
|
|
53
|
+
Reflect.defineMetadata(MCP_HANDLERS_METADATA, handlers, target.constructor);
|
|
54
|
+
return descriptor;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get prompt metadata from a method
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export function getMCPPromptMetadata(target, propertyKey) {
|
|
62
|
+
return Reflect.getMetadata(MCP_PROMPT_METADATA, target.prototype, propertyKey);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=mcp-prompt.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-prompt.decorator.js","sourceRoot":"","sources":["../../src/decorators/mcp-prompt.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAG7E;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,OAAO,CACL,MAAc,EACd,WAA4B,EAC5B,UAA8B,EACV,EAAE;QACtB,sCAAsC;QACtC,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAE1E,0CAA0C;QAC1C,MAAM,QAAQ,GACZ,OAAO,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAEvE,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QAC3D,OAAO,CAAC,cAAc,CAAC,qBAAqB,EAAE,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QAE5E,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAgB,EAChB,WAA4B;IAE5B,OAAO,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AACjF,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @MCPResource Decorator
|
|
3
|
+
*
|
|
4
|
+
* Marks a method as an MCP resource provider.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Injectable } from '@riktajs/core';
|
|
9
|
+
* import { MCPResource } from '@riktajs/mcp';
|
|
10
|
+
*
|
|
11
|
+
* @Injectable()
|
|
12
|
+
* class FileService {
|
|
13
|
+
* @MCPResource({
|
|
14
|
+
* uriPattern: 'file://read',
|
|
15
|
+
* name: 'Read File',
|
|
16
|
+
* description: 'Read file contents by path',
|
|
17
|
+
* mimeType: 'text/plain'
|
|
18
|
+
* })
|
|
19
|
+
* async readFile(uri: string) {
|
|
20
|
+
* const url = new URL(uri);
|
|
21
|
+
* const filePath = url.searchParams.get('path');
|
|
22
|
+
* const content = await fs.readFile(filePath!, 'utf-8');
|
|
23
|
+
* return {
|
|
24
|
+
* contents: [{
|
|
25
|
+
* uri,
|
|
26
|
+
* text: content,
|
|
27
|
+
* mimeType: 'text/plain'
|
|
28
|
+
* }]
|
|
29
|
+
* };
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
import 'reflect-metadata';
|
|
35
|
+
import type { MCPResourceOptions } from '../types.js';
|
|
36
|
+
/**
|
|
37
|
+
* @MCPResource() decorator
|
|
38
|
+
*
|
|
39
|
+
* Registers a method as an MCP resource provider.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Resource configuration options
|
|
42
|
+
*/
|
|
43
|
+
export declare function MCPResource(options: MCPResourceOptions): MethodDecorator;
|
|
44
|
+
/**
|
|
45
|
+
* Get resource metadata from a method
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare function getMCPResourceMetadata(target: Function, propertyKey: string | symbol): MCPResourceOptions | undefined;
|
|
49
|
+
//# sourceMappingURL=mcp-resource.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-resource.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/mcp-resource.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAwBxE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,QAAQ,EAChB,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,kBAAkB,GAAG,SAAS,CAEhC"}
|