@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,48 @@
1
+ /**
2
+ * @riktajs/mcp - Zod to JSON Schema Conversion
3
+ *
4
+ * Utilities for converting Zod schemas to JSON Schema format
5
+ * compatible with @platformatic/mcp.
6
+ */
7
+ import type { ZodType, ZodTypeDef } from 'zod';
8
+ import { type JsonSchema7Type } from 'zod-to-json-schema';
9
+ /**
10
+ * Type guard to check if a value is a Zod schema
11
+ * Uses duck typing to detect Zod schemas without requiring the full library
12
+ */
13
+ export declare function isZodSchema(value: unknown): value is ZodType<unknown, ZodTypeDef, unknown>;
14
+ /**
15
+ * Convert a Zod schema to JSON Schema format for MCP
16
+ *
17
+ * @param schema - The Zod schema to convert
18
+ * @returns JSON Schema object compatible with MCP
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { z } from 'zod';
23
+ *
24
+ * const schema = z.object({
25
+ * path: z.string().describe('File path'),
26
+ * encoding: z.string().optional(),
27
+ * });
28
+ *
29
+ * const jsonSchema = zodToMCPSchema(schema);
30
+ * // {
31
+ * // type: 'object',
32
+ * // properties: {
33
+ * // path: { type: 'string', description: 'File path' },
34
+ * // encoding: { type: 'string' }
35
+ * // },
36
+ * // required: ['path']
37
+ * // }
38
+ * ```
39
+ */
40
+ export declare function zodToMCPSchema(schema: ZodType): JsonSchema7Type;
41
+ /**
42
+ * Convert a Zod schema to JSON Schema, or return undefined if not a Zod schema
43
+ *
44
+ * @param schemaOrUndefined - The Zod schema or undefined
45
+ * @returns JSON Schema object or undefined
46
+ */
47
+ export declare function toMCPSchema(schemaOrUndefined: ZodType | undefined): JsonSchema7Type | undefined;
48
+ //# sourceMappingURL=zod-to-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-to-schema.d.ts","sourceRoot":"","sources":["../../src/utils/zod-to-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC/C,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE3E;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAQ1F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,CAc/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,iBAAiB,EAAE,OAAO,GAAG,SAAS,GACrC,eAAe,GAAG,SAAS,CAU7B"}
@@ -0,0 +1,67 @@
1
+ import { zodToJsonSchema } from 'zod-to-json-schema';
2
+ /**
3
+ * Type guard to check if a value is a Zod schema
4
+ * Uses duck typing to detect Zod schemas without requiring the full library
5
+ */
6
+ export function isZodSchema(value) {
7
+ return (value !== null &&
8
+ typeof value === 'object' &&
9
+ '_def' in value &&
10
+ 'safeParse' in value &&
11
+ typeof value.safeParse === 'function');
12
+ }
13
+ /**
14
+ * Convert a Zod schema to JSON Schema format for MCP
15
+ *
16
+ * @param schema - The Zod schema to convert
17
+ * @returns JSON Schema object compatible with MCP
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { z } from 'zod';
22
+ *
23
+ * const schema = z.object({
24
+ * path: z.string().describe('File path'),
25
+ * encoding: z.string().optional(),
26
+ * });
27
+ *
28
+ * const jsonSchema = zodToMCPSchema(schema);
29
+ * // {
30
+ * // type: 'object',
31
+ * // properties: {
32
+ * // path: { type: 'string', description: 'File path' },
33
+ * // encoding: { type: 'string' }
34
+ * // },
35
+ * // required: ['path']
36
+ * // }
37
+ * ```
38
+ */
39
+ export function zodToMCPSchema(schema) {
40
+ const jsonSchema = zodToJsonSchema(schema, {
41
+ target: 'jsonSchema7',
42
+ $refStrategy: 'none', // Inline all references
43
+ });
44
+ // Remove $schema property as MCP doesn't need it
45
+ if (typeof jsonSchema === 'object' && jsonSchema !== null) {
46
+ const result = { ...jsonSchema };
47
+ delete result.$schema;
48
+ return result;
49
+ }
50
+ return jsonSchema;
51
+ }
52
+ /**
53
+ * Convert a Zod schema to JSON Schema, or return undefined if not a Zod schema
54
+ *
55
+ * @param schemaOrUndefined - The Zod schema or undefined
56
+ * @returns JSON Schema object or undefined
57
+ */
58
+ export function toMCPSchema(schemaOrUndefined) {
59
+ if (!schemaOrUndefined) {
60
+ return undefined;
61
+ }
62
+ if (isZodSchema(schemaOrUndefined)) {
63
+ return zodToMCPSchema(schemaOrUndefined);
64
+ }
65
+ return undefined;
66
+ }
67
+ //# sourceMappingURL=zod-to-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-to-schema.js","sourceRoot":"","sources":["../../src/utils/zod-to-schema.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAwB,MAAM,oBAAoB,CAAC;AAE3E;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,IAAI,KAAK;QACf,WAAW,IAAI,KAAK;QACpB,OAAQ,KAAgC,CAAC,SAAS,KAAK,UAAU,CAClE,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,cAAc,CAAC,MAAe;IAC5C,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,EAAE;QACzC,MAAM,EAAE,aAAa;QACrB,YAAY,EAAE,MAAM,EAAE,wBAAwB;KAC/C,CAAC,CAAC;IAEH,iDAAiD;IACjD,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QAC1D,MAAM,MAAM,GAAG,EAAE,GAAG,UAAU,EAA6B,CAAC;QAC5D,OAAO,MAAM,CAAC,OAAO,CAAC;QACtB,OAAO,MAAyB,CAAC;IACnC,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,iBAAsC;IAEtC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,WAAW,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACnC,OAAO,cAAc,CAAC,iBAAiB,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@riktajs/mcp",
3
+ "version": "0.1.0",
4
+ "description": "Model Context Protocol (MCP) integration for Rikta Framework - Connect AI assistants to your backend",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "clean": "rm -rf dist",
13
+ "prebuild": "npm run clean",
14
+ "build": "tsc",
15
+ "dev": "tsc --watch",
16
+ "test": "vitest run",
17
+ "test:watch": "vitest",
18
+ "test:coverage": "vitest run --coverage",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "keywords": [
22
+ "rikta",
23
+ "mcp",
24
+ "model-context-protocol",
25
+ "ai",
26
+ "llm",
27
+ "fastify",
28
+ "typescript",
29
+ "decorators",
30
+ "tools",
31
+ "resources",
32
+ "prompts"
33
+ ],
34
+ "author": "",
35
+ "license": "MIT",
36
+ "peerDependencies": {
37
+ "@riktajs/core": ">=0.4.3",
38
+ "fastify": ">=5.0.0",
39
+ "reflect-metadata": ">=0.2.0",
40
+ "zod": ">=3.20.0"
41
+ },
42
+ "dependencies": {
43
+ "@platformatic/mcp": "^1.0.0",
44
+ "fastify-plugin": "^5.0.1",
45
+ "zod-to-json-schema": "^3.25.1"
46
+ },
47
+ "devDependencies": {
48
+ "@riktajs/core": "*",
49
+ "@types/node": "^22.10.2",
50
+ "@vitest/coverage-v8": "^2.1.9",
51
+ "fastify": "^5.3.2",
52
+ "reflect-metadata": "^0.2.2",
53
+ "typescript": "^5.7.2",
54
+ "vitest": "^2.1.8",
55
+ "zod": "^3.25.76"
56
+ },
57
+ "engines": {
58
+ "node": ">=22.0.0"
59
+ },
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "https://github.com/riktahq/rikta.git",
63
+ "directory": "packages/mcp"
64
+ }
65
+ }