@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.
Files changed (54) hide show
  1. package/README.md +399 -0
  2. package/dist/constants.d.ts +23 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +23 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/decorators/index.d.ts +9 -0
  7. package/dist/decorators/index.d.ts.map +1 -0
  8. package/dist/decorators/index.js +12 -0
  9. package/dist/decorators/index.js.map +1 -0
  10. package/dist/decorators/mcp-prompt.decorator.d.ts +52 -0
  11. package/dist/decorators/mcp-prompt.decorator.d.ts.map +1 -0
  12. package/dist/decorators/mcp-prompt.decorator.js +64 -0
  13. package/dist/decorators/mcp-prompt.decorator.js.map +1 -0
  14. package/dist/decorators/mcp-resource.decorator.d.ts +49 -0
  15. package/dist/decorators/mcp-resource.decorator.d.ts.map +1 -0
  16. package/dist/decorators/mcp-resource.decorator.js +66 -0
  17. package/dist/decorators/mcp-resource.decorator.js.map +1 -0
  18. package/dist/decorators/mcp-tool.decorator.d.ts +45 -0
  19. package/dist/decorators/mcp-tool.decorator.d.ts.map +1 -0
  20. package/dist/decorators/mcp-tool.decorator.js +57 -0
  21. package/dist/decorators/mcp-tool.decorator.js.map +1 -0
  22. package/dist/discovery/index.d.ts +7 -0
  23. package/dist/discovery/index.d.ts.map +1 -0
  24. package/dist/discovery/index.js +7 -0
  25. package/dist/discovery/index.js.map +1 -0
  26. package/dist/discovery/mcp-registry.d.ts +80 -0
  27. package/dist/discovery/mcp-registry.d.ts.map +1 -0
  28. package/dist/discovery/mcp-registry.js +179 -0
  29. package/dist/discovery/mcp-registry.js.map +1 -0
  30. package/dist/index.d.ts +76 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +81 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/plugin/index.d.ts +7 -0
  35. package/dist/plugin/index.d.ts.map +1 -0
  36. package/dist/plugin/index.js +7 -0
  37. package/dist/plugin/index.js.map +1 -0
  38. package/dist/plugin/mcp.plugin.d.ts +72 -0
  39. package/dist/plugin/mcp.plugin.d.ts.map +1 -0
  40. package/dist/plugin/mcp.plugin.js +198 -0
  41. package/dist/plugin/mcp.plugin.js.map +1 -0
  42. package/dist/types.d.ts +337 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/types.js +7 -0
  45. package/dist/types.js.map +1 -0
  46. package/dist/utils/index.d.ts +7 -0
  47. package/dist/utils/index.d.ts.map +1 -0
  48. package/dist/utils/index.js +7 -0
  49. package/dist/utils/index.js.map +1 -0
  50. package/dist/utils/zod-to-schema.d.ts +48 -0
  51. package/dist/utils/zod-to-schema.d.ts.map +1 -0
  52. package/dist/utils/zod-to-schema.js +67 -0
  53. package/dist/utils/zod-to-schema.js.map +1 -0
  54. package/package.json +65 -0
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @riktajs/mcp - MCP Plugin
3
+ *
4
+ * Main plugin that integrates @platformatic/mcp with Rikta Framework.
5
+ * Provides registerMCPServer function for easy MCP setup.
6
+ */
7
+ import type { FastifyInstance } from 'fastify';
8
+ import type { MCPServerOptions, RiktaApplication } from '../types.js';
9
+ import '@platformatic/mcp';
10
+ type Constructor<T = unknown> = new (...args: unknown[]) => T;
11
+ interface Container {
12
+ resolve<T>(target: Constructor<T>): T;
13
+ }
14
+ /**
15
+ * MCP plugin implementation for Fastify
16
+ *
17
+ * Registers @platformatic/mcp and auto-discovers MCP handlers from Rikta services.
18
+ */
19
+ declare function mcpPluginImpl(fastify: FastifyInstance, options: MCPServerOptions & {
20
+ container?: Container;
21
+ }): Promise<void>;
22
+ /**
23
+ * Wrapped Fastify plugin with proper encapsulation
24
+ */
25
+ export declare const mcpServerPlugin: typeof mcpPluginImpl;
26
+ /**
27
+ * Register MCP server with a Rikta application
28
+ *
29
+ * This is the main entry point for integrating MCP with Rikta.
30
+ * It decorates the Fastify instance with @platformatic/mcp and
31
+ * auto-discovers MCP handlers from @Injectable classes.
32
+ *
33
+ * @param app - Rikta application instance
34
+ * @param options - MCP server options
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * import { Rikta } from '@riktajs/core';
39
+ * import { registerMCPServer } from '@riktajs/mcp';
40
+ *
41
+ * const app = await Rikta.create({ port: 3000 });
42
+ *
43
+ * await registerMCPServer(app, {
44
+ * serverInfo: { name: 'my-mcp-server', version: '1.0.0' },
45
+ * instructions: 'This server provides file system tools',
46
+ * enableSSE: true,
47
+ * });
48
+ *
49
+ * await app.listen();
50
+ * // MCP available at http://localhost:3000/mcp
51
+ * ```
52
+ */
53
+ export declare function registerMCPServer(app: RiktaApplication, options?: MCPServerOptions): Promise<void>;
54
+ /**
55
+ * Create MCP configuration object
56
+ *
57
+ * Helper function to create type-safe MCP configuration.
58
+ *
59
+ * @param options - MCP server options
60
+ * @returns Validated MCP configuration
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const mcpConfig = createMCPConfig({
65
+ * serverInfo: { name: 'my-server', version: '1.0.0' },
66
+ * redis: { host: 'localhost', port: 6379 },
67
+ * });
68
+ * ```
69
+ */
70
+ export declare function createMCPConfig(options: MCPServerOptions): MCPServerOptions;
71
+ export {};
72
+ //# sourceMappingURL=mcp.plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/mcp.plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAS/C,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AAGrB,OAAO,mBAAmB,CAAC;AAG3B,KAAK,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAG9D,UAAU,SAAS;IACjB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CACvC;AAaD;;;;GAIG;AACH,iBAAe,aAAa,CAC1B,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,gBAAgB,GAAG;IAAE,SAAS,CAAC,EAAE,SAAS,CAAA;CAAE,GACpD,OAAO,CAAC,IAAI,CAAC,CAkIf;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,sBAG1B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,gBAAgB,EACrB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAK3E"}
@@ -0,0 +1,198 @@
1
+ import fp from 'fastify-plugin';
2
+ import mcpPlugin from '@platformatic/mcp';
3
+ import { registry } from '@riktajs/core';
4
+ import { mcpRegistry } from '../discovery/mcp-registry.js';
5
+ import { toMCPSchema } from '../utils/zod-to-schema.js';
6
+ import { DEFAULT_MCP_PATH, DEFAULT_SERVER_INFO, MCP_HANDLERS_METADATA } from '../constants.js';
7
+ // Re-export types from @platformatic/mcp for module augmentation
8
+ import '@platformatic/mcp';
9
+ /**
10
+ * Default options for MCP server
11
+ */
12
+ const DEFAULT_OPTIONS = {
13
+ enableSSE: true,
14
+ path: DEFAULT_MCP_PATH,
15
+ heartbeat: true,
16
+ heartbeatInterval: 30000,
17
+ sessionTTL: 3600,
18
+ };
19
+ /**
20
+ * MCP plugin implementation for Fastify
21
+ *
22
+ * Registers @platformatic/mcp and auto-discovers MCP handlers from Rikta services.
23
+ */
24
+ async function mcpPluginImpl(fastify, options) {
25
+ const mergedOptions = { ...DEFAULT_OPTIONS, ...options };
26
+ const { serverInfo, capabilities, instructions, enableSSE, redis, container } = mergedOptions;
27
+ // Build capabilities based on registered handlers
28
+ const effectiveCapabilities = capabilities || {};
29
+ // We'll populate capabilities after scanning
30
+ // Build MCP plugin options
31
+ const mcpOptions = {
32
+ serverInfo: serverInfo || DEFAULT_SERVER_INFO,
33
+ capabilities: effectiveCapabilities,
34
+ enableSSE,
35
+ };
36
+ // Add instructions if provided
37
+ if (instructions) {
38
+ mcpOptions.instructions = instructions;
39
+ }
40
+ // Add Redis config if provided
41
+ if (redis) {
42
+ mcpOptions.redis = {
43
+ host: redis.host,
44
+ port: redis.port || 6379,
45
+ password: redis.password,
46
+ db: redis.db || 0,
47
+ };
48
+ }
49
+ // Register @platformatic/mcp plugin
50
+ await fastify.register(mcpPlugin, mcpOptions);
51
+ // Scan all providers from Rikta registry for MCP handlers
52
+ if (container) {
53
+ const providers = registry.getProviders();
54
+ for (const providerClass of providers) {
55
+ // Check if this provider has MCP handlers
56
+ const handlers = Reflect.getMetadata(MCP_HANDLERS_METADATA, providerClass);
57
+ if (handlers && handlers.length > 0) {
58
+ // Resolve the provider instance from the container
59
+ const instance = container.resolve(providerClass);
60
+ mcpRegistry.scanClass(providerClass, instance);
61
+ }
62
+ }
63
+ }
64
+ // Register all discovered tools
65
+ const tools = mcpRegistry.getTools();
66
+ for (const tool of tools) {
67
+ // Convert Zod schema to JSON Schema for MCP
68
+ const inputSchema = toMCPSchema(tool.inputSchema);
69
+ const handler = async (params, context) => {
70
+ const result = await tool.handler(params, context);
71
+ return result;
72
+ };
73
+ fastify.mcpAddTool({
74
+ name: tool.name,
75
+ description: tool.description,
76
+ inputSchema,
77
+ }, handler);
78
+ }
79
+ // Register all discovered resources
80
+ const resources = mcpRegistry.getResources();
81
+ for (const resource of resources) {
82
+ // Convert Zod schema to JSON Schema for MCP (uriSchema is not needed for resources)
83
+ const handler = async (uri, context) => {
84
+ const result = await resource.handler(uri, context);
85
+ return result;
86
+ };
87
+ fastify.mcpAddResource({
88
+ uriPattern: resource.uriPattern,
89
+ name: resource.name,
90
+ description: resource.description,
91
+ mimeType: resource.mimeType,
92
+ }, handler);
93
+ }
94
+ // Register all discovered prompts
95
+ const prompts = mcpRegistry.getPrompts();
96
+ for (const prompt of prompts) {
97
+ const handler = async (name, args, context) => {
98
+ const result = await prompt.handler(args, context);
99
+ return result;
100
+ };
101
+ fastify.mcpAddPrompt({
102
+ name: prompt.name,
103
+ description: prompt.description,
104
+ }, handler);
105
+ }
106
+ // Update capabilities based on what was registered
107
+ if (tools.length > 0) {
108
+ effectiveCapabilities.tools = {};
109
+ }
110
+ if (resources.length > 0) {
111
+ effectiveCapabilities.resources = {};
112
+ }
113
+ if (prompts.length > 0) {
114
+ effectiveCapabilities.prompts = {};
115
+ }
116
+ // Log registration summary
117
+ const stats = mcpRegistry.getStats();
118
+ if (stats.tools > 0 || stats.resources > 0 || stats.prompts > 0) {
119
+ console.log(`\n🤖 MCP Server registered:`);
120
+ console.log(` 📍 Endpoint: ${mergedOptions.path}`);
121
+ if (stats.tools > 0)
122
+ console.log(` 🔧 Tools: ${stats.tools}`);
123
+ if (stats.resources > 0)
124
+ console.log(` 📁 Resources: ${stats.resources}`);
125
+ if (stats.prompts > 0)
126
+ console.log(` 💬 Prompts: ${stats.prompts}`);
127
+ if (redis)
128
+ console.log(` 📡 Redis: ${redis.host}:${redis.port || 6379}`);
129
+ console.log('');
130
+ }
131
+ }
132
+ /**
133
+ * Wrapped Fastify plugin with proper encapsulation
134
+ */
135
+ export const mcpServerPlugin = fp(mcpPluginImpl, {
136
+ name: '@riktajs/mcp',
137
+ fastify: '5.x',
138
+ });
139
+ /**
140
+ * Register MCP server with a Rikta application
141
+ *
142
+ * This is the main entry point for integrating MCP with Rikta.
143
+ * It decorates the Fastify instance with @platformatic/mcp and
144
+ * auto-discovers MCP handlers from @Injectable classes.
145
+ *
146
+ * @param app - Rikta application instance
147
+ * @param options - MCP server options
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * import { Rikta } from '@riktajs/core';
152
+ * import { registerMCPServer } from '@riktajs/mcp';
153
+ *
154
+ * const app = await Rikta.create({ port: 3000 });
155
+ *
156
+ * await registerMCPServer(app, {
157
+ * serverInfo: { name: 'my-mcp-server', version: '1.0.0' },
158
+ * instructions: 'This server provides file system tools',
159
+ * enableSSE: true,
160
+ * });
161
+ *
162
+ * await app.listen();
163
+ * // MCP available at http://localhost:3000/mcp
164
+ * ```
165
+ */
166
+ export async function registerMCPServer(app, options = {}) {
167
+ // Get the container from the app using getContainer method
168
+ const container = 'getContainer' in app
169
+ ? app.getContainer()
170
+ : undefined;
171
+ await app.server.register(mcpServerPlugin, {
172
+ ...options,
173
+ container,
174
+ });
175
+ }
176
+ /**
177
+ * Create MCP configuration object
178
+ *
179
+ * Helper function to create type-safe MCP configuration.
180
+ *
181
+ * @param options - MCP server options
182
+ * @returns Validated MCP configuration
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * const mcpConfig = createMCPConfig({
187
+ * serverInfo: { name: 'my-server', version: '1.0.0' },
188
+ * redis: { host: 'localhost', port: 6379 },
189
+ * });
190
+ * ```
191
+ */
192
+ export function createMCPConfig(options) {
193
+ return {
194
+ ...DEFAULT_OPTIONS,
195
+ ...options,
196
+ };
197
+ }
198
+ //# sourceMappingURL=mcp.plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.plugin.js","sourceRoot":"","sources":["../../src/plugin/mcp.plugin.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChC,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAO/F,iEAAiE;AACjE,OAAO,mBAAmB,CAAC;AAU3B;;GAEG;AACH,MAAM,eAAe,GAA8G;IACjI,SAAS,EAAE,IAAI;IACf,I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C"}
@@ -0,0 +1,337 @@
1
+ /**
2
+ * @riktajs/mcp - Type Definitions
3
+ *
4
+ * TypeScript interfaces and types for MCP integration.
5
+ */
6
+ import type { ZodType, ZodTypeDef } from 'zod';
7
+ /**
8
+ * Generic Zod schema type
9
+ */
10
+ export type ZodSchema = ZodType<unknown, ZodTypeDef, unknown>;
11
+ /**
12
+ * Options for @MCPTool decorator
13
+ */
14
+ export interface MCPToolOptions {
15
+ /**
16
+ * Unique name for the tool
17
+ */
18
+ name: string;
19
+ /**
20
+ * Human-readable description of what the tool does
21
+ */
22
+ description: string;
23
+ /**
24
+ * Zod schema for input validation (optional)
25
+ * If not provided, the tool accepts no arguments
26
+ */
27
+ inputSchema?: ZodSchema;
28
+ }
29
+ /**
30
+ * MCP Tool handler function signature
31
+ */
32
+ export type MCPToolHandler<TParams = unknown> = (params: TParams, context?: MCPHandlerContext) => Promise<MCPToolResult> | MCPToolResult;
33
+ /**
34
+ * Result returned from an MCP tool
35
+ */
36
+ export interface MCPToolResult {
37
+ content: MCPContent[];
38
+ isError?: boolean;
39
+ }
40
+ /**
41
+ * Options for @MCPResource decorator
42
+ */
43
+ export interface MCPResourceOptions {
44
+ /**
45
+ * URI pattern for the resource (e.g., 'file://read', 'db://users')
46
+ */
47
+ uriPattern: string;
48
+ /**
49
+ * Human-readable name for the resource
50
+ */
51
+ name: string;
52
+ /**
53
+ * Description of the resource
54
+ */
55
+ description: string;
56
+ /**
57
+ * MIME type of the resource content
58
+ * @default 'text/plain'
59
+ */
60
+ mimeType?: string;
61
+ /**
62
+ * Zod schema for URI validation (optional)
63
+ */
64
+ uriSchema?: ZodSchema;
65
+ }
66
+ /**
67
+ * MCP Resource handler function signature
68
+ */
69
+ export type MCPResourceHandler = (uri: string, context?: MCPHandlerContext) => Promise<MCPResourceResult> | MCPResourceResult;
70
+ /**
71
+ * Result returned from an MCP resource
72
+ */
73
+ export interface MCPResourceResult {
74
+ contents: MCPResourceContent[];
75
+ }
76
+ /**
77
+ * Content item in a resource result
78
+ */
79
+ export interface MCPResourceContent {
80
+ uri: string;
81
+ text?: string;
82
+ blob?: string;
83
+ mimeType: string;
84
+ }
85
+ /**
86
+ * Options for @MCPPrompt decorator
87
+ */
88
+ export interface MCPPromptOptions {
89
+ /**
90
+ * Unique name for the prompt
91
+ */
92
+ name: string;
93
+ /**
94
+ * Human-readable description of the prompt
95
+ */
96
+ description: string;
97
+ /**
98
+ * Arguments the prompt accepts
99
+ */
100
+ arguments?: MCPPromptArgument[];
101
+ }
102
+ /**
103
+ * Prompt argument definition
104
+ */
105
+ export interface MCPPromptArgument {
106
+ /**
107
+ * Argument name
108
+ */
109
+ name: string;
110
+ /**
111
+ * Argument description
112
+ */
113
+ description?: string;
114
+ /**
115
+ * Whether the argument is required
116
+ * @default false
117
+ */
118
+ required?: boolean;
119
+ }
120
+ /**
121
+ * MCP Prompt handler function signature
122
+ */
123
+ export type MCPPromptHandler<TArgs = Record<string, string>> = (args: TArgs, context?: MCPHandlerContext) => Promise<MCPPromptResult> | MCPPromptResult;
124
+ /**
125
+ * Result returned from an MCP prompt
126
+ */
127
+ export interface MCPPromptResult {
128
+ messages: MCPPromptMessage[];
129
+ description?: string;
130
+ }
131
+ /**
132
+ * Message in a prompt result
133
+ */
134
+ export interface MCPPromptMessage {
135
+ role: 'user' | 'assistant';
136
+ content: MCPContent;
137
+ }
138
+ /**
139
+ * Content types supported by MCP
140
+ */
141
+ export type MCPContent = MCPTextContent | MCPImageContent | MCPAudioContent | MCPEmbeddedResource;
142
+ /**
143
+ * Text content
144
+ */
145
+ export interface MCPTextContent {
146
+ type: 'text';
147
+ text: string;
148
+ }
149
+ /**
150
+ * Image content
151
+ */
152
+ export interface MCPImageContent {
153
+ type: 'image';
154
+ data: string;
155
+ mimeType: string;
156
+ }
157
+ /**
158
+ * Audio content
159
+ */
160
+ export interface MCPAudioContent {
161
+ type: 'audio';
162
+ data: string;
163
+ mimeType: string;
164
+ }
165
+ /**
166
+ * Embedded resource content
167
+ */
168
+ export interface MCPEmbeddedResource {
169
+ type: 'resource';
170
+ resource: {
171
+ uri: string;
172
+ text?: string;
173
+ blob?: string;
174
+ mimeType?: string;
175
+ };
176
+ }
177
+ /**
178
+ * Context passed to MCP handlers
179
+ */
180
+ export interface MCPHandlerContext {
181
+ /**
182
+ * Session ID for SSE connections
183
+ */
184
+ sessionId?: string;
185
+ /**
186
+ * Send a notification to the current session
187
+ */
188
+ sendNotification?: (method: string, params: unknown) => void;
189
+ }
190
+ /**
191
+ * Redis configuration for horizontal scaling
192
+ */
193
+ export interface MCPRedisConfig {
194
+ /**
195
+ * Redis host
196
+ */
197
+ host: string;
198
+ /**
199
+ * Redis port
200
+ * @default 6379
201
+ */
202
+ port?: number;
203
+ /**
204
+ * Redis password (optional)
205
+ */
206
+ password?: string;
207
+ /**
208
+ * Redis database number
209
+ * @default 0
210
+ */
211
+ db?: number;
212
+ }
213
+ /**
214
+ * Server info for MCP protocol
215
+ */
216
+ export interface MCPServerInfo {
217
+ /**
218
+ * Server name
219
+ */
220
+ name: string;
221
+ /**
222
+ * Server version
223
+ */
224
+ version: string;
225
+ }
226
+ /**
227
+ * MCP server capabilities
228
+ */
229
+ export interface MCPCapabilities {
230
+ /**
231
+ * Enable tools capability
232
+ */
233
+ tools?: Record<string, unknown>;
234
+ /**
235
+ * Enable resources capability
236
+ */
237
+ resources?: Record<string, unknown>;
238
+ /**
239
+ * Enable prompts capability
240
+ */
241
+ prompts?: Record<string, unknown>;
242
+ /**
243
+ * Enable logging capability
244
+ */
245
+ logging?: Record<string, unknown>;
246
+ }
247
+ /**
248
+ * Options for registerMCPServer function
249
+ */
250
+ export interface MCPServerOptions {
251
+ /**
252
+ * Server info for MCP protocol
253
+ */
254
+ serverInfo?: MCPServerInfo;
255
+ /**
256
+ * Server capabilities
257
+ */
258
+ capabilities?: MCPCapabilities;
259
+ /**
260
+ * Instructions for AI assistants
261
+ */
262
+ instructions?: string;
263
+ /**
264
+ * Enable SSE (Server-Sent Events) transport
265
+ * @default true
266
+ */
267
+ enableSSE?: boolean;
268
+ /**
269
+ * Redis configuration for horizontal scaling
270
+ * When provided, enables cross-instance session management
271
+ */
272
+ redis?: MCPRedisConfig;
273
+ /**
274
+ * Custom MCP endpoint path
275
+ * @default '/mcp'
276
+ */
277
+ path?: string;
278
+ /**
279
+ * Session TTL in seconds
280
+ * @default 3600
281
+ */
282
+ sessionTTL?: number;
283
+ /**
284
+ * Enable heartbeat for SSE connections
285
+ * @default true
286
+ */
287
+ heartbeat?: boolean;
288
+ /**
289
+ * Heartbeat interval in milliseconds
290
+ * @default 30000
291
+ */
292
+ heartbeatInterval?: number;
293
+ }
294
+ /**
295
+ * Registered MCP tool metadata
296
+ */
297
+ export interface RegisteredMCPTool {
298
+ name: string;
299
+ description: string;
300
+ inputSchema?: ZodSchema;
301
+ handler: MCPToolHandler;
302
+ targetClass: Function;
303
+ methodName: string | symbol;
304
+ }
305
+ /**
306
+ * Registered MCP resource metadata
307
+ */
308
+ export interface RegisteredMCPResource {
309
+ uriPattern: string;
310
+ name: string;
311
+ description: string;
312
+ mimeType: string;
313
+ uriSchema?: ZodSchema;
314
+ handler: MCPResourceHandler;
315
+ targetClass: Function;
316
+ methodName: string | symbol;
317
+ }
318
+ /**
319
+ * Registered MCP prompt metadata
320
+ */
321
+ export interface RegisteredMCPPrompt {
322
+ name: string;
323
+ description: string;
324
+ arguments?: MCPPromptArgument[];
325
+ handler: MCPPromptHandler;
326
+ targetClass: Function;
327
+ methodName: string | symbol;
328
+ }
329
+ /**
330
+ * Rikta Application type (minimal interface for type safety)
331
+ * Uses a generic server type to avoid strict FastifyInstance compatibility issues
332
+ * between different packages that may extend FastifyInstance differently.
333
+ */
334
+ export interface RiktaApplication {
335
+ server: any;
336
+ }
337
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,O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CAAC;IAC1B,WAAW,EAAE,QAAQ,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B;AAMD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAE/B,MAAM,EAAE,GAAG,CAAC;CACb"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @riktajs/mcp - Type Definitions
3
+ *
4
+ * TypeScript interfaces and types for MCP integration.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @riktajs/mcp - Utilities
3
+ *
4
+ * Export utility functions.
5
+ */
6
+ export { zodToMCPSchema, toMCPSchema, isZodSchema } from './zod-to-schema.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @riktajs/mcp - Utilities
3
+ *
4
+ * Export utility functions.
5
+ */
6
+ export { zodToMCPSchema, toMCPSchema, isZodSchema } from './zod-to-schema.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}