modality-mcp-kit 0.0.1
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 +85 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/schemas/schemas_tool_config.d.ts +68 -0
- package/dist/schemas/schemas_tool_config.js +1 -0
- package/dist/util_mcp_tools_converter.d.ts +28 -0
- package/dist/util_mcp_tools_converter.js +38 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Modality MCP Kit
|
|
2
|
+
|
|
3
|
+
Schema conversion utilities for MCP tool development with multi-library support. Provides universal JSON Schema conversion via xsschema and AITool-to-FastMCP transformation utilities.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Universal Schema Conversion**: Convert Zod, Valibot, ArkType, Effect, and Sury schemas to JSON Schema via `xsschema`
|
|
8
|
+
- **MCP Tool Registration**: Transform AITool definitions to FastMCP-compatible format
|
|
9
|
+
- **Type-Safe**: Full TypeScript support with preserved schema types
|
|
10
|
+
- **Lightweight**: Minimal dependencies, focused on MCP tool development
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install modality-mcp-kit
|
|
16
|
+
# or
|
|
17
|
+
bun add modality-mcp-kit
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Schema Conversion
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { toJsonSchema } from "modality-mcp-kit";
|
|
26
|
+
import { z } from "zod";
|
|
27
|
+
|
|
28
|
+
const userSchema = z.object({
|
|
29
|
+
id: z.string(),
|
|
30
|
+
name: z.string(),
|
|
31
|
+
age: z.number(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const jsonSchema = toJsonSchema(userSchema);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### MCP Tool Setup
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { setupAITools, ModalityFastMCP } from "modality-mcp-kit";
|
|
41
|
+
import { z } from "zod";
|
|
42
|
+
|
|
43
|
+
const mcp = new ModalityFastMCP();
|
|
44
|
+
|
|
45
|
+
const aiTools = {
|
|
46
|
+
getUserById: {
|
|
47
|
+
name: "get_user",
|
|
48
|
+
description: "Get user by ID",
|
|
49
|
+
inputSchema: z.object({ id: z.string() }),
|
|
50
|
+
execute: async (args) => {
|
|
51
|
+
return { id: args.id, name: "John" };
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Registers tools with MCP server and transforms inputSchema → parameters
|
|
57
|
+
setupAITools(aiTools, mcp);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## API
|
|
61
|
+
|
|
62
|
+
### `toJsonSchema(schema)`
|
|
63
|
+
|
|
64
|
+
Converts any supported schema (Zod, Valibot, ArkType, Effect, Sury) to JSON Schema.
|
|
65
|
+
|
|
66
|
+
### `setupAITools(aiTools, mcpServer?)`
|
|
67
|
+
|
|
68
|
+
Transforms AITool definitions to FastMCP format:
|
|
69
|
+
- Converts `inputSchema` to `parameters`
|
|
70
|
+
- Uses key as `name` if not specified
|
|
71
|
+
- Registers with optional MCP server
|
|
72
|
+
|
|
73
|
+
### `ModalityFastMCP`
|
|
74
|
+
|
|
75
|
+
FastMCP-compatible implementation with `addTool()` and `getTools()` methods.
|
|
76
|
+
|
|
77
|
+
## Repository
|
|
78
|
+
|
|
79
|
+
- **GitHub**: https://github.com/react-atomic/modality
|
|
80
|
+
- **NPM**: https://www.npmjs.com/package/modality-mcp-kit
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
|
85
|
+
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy of StandardSchemaV1 interface for compatibility
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export interface ToolParameters<Input = unknown, Output = Input> {
|
|
6
|
+
readonly "~standard": ToolParameters.Props<Input, Output>;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace ToolParameters {
|
|
9
|
+
interface Props<Input = unknown, Output = Input> {
|
|
10
|
+
readonly version: 1;
|
|
11
|
+
readonly vendor: string;
|
|
12
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
13
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
14
|
+
}
|
|
15
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
16
|
+
interface SuccessResult<Output> {
|
|
17
|
+
readonly value: Output;
|
|
18
|
+
readonly issues?: undefined;
|
|
19
|
+
}
|
|
20
|
+
interface FailureResult {
|
|
21
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
22
|
+
}
|
|
23
|
+
interface Issue {
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
26
|
+
}
|
|
27
|
+
interface PathSegment {
|
|
28
|
+
readonly key: PropertyKey;
|
|
29
|
+
}
|
|
30
|
+
interface Types<Input = unknown, Output = Input> {
|
|
31
|
+
readonly input: Input;
|
|
32
|
+
readonly output: Output;
|
|
33
|
+
}
|
|
34
|
+
type InferInput<Schema extends ToolParameters> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
35
|
+
type InferOutput<Schema extends ToolParameters> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Tool interface for AI SDK compatibility
|
|
39
|
+
*/
|
|
40
|
+
export interface AITool<T extends Record<string, unknown> | undefined = any, TParams extends ToolParameters = z.ZodSchema> {
|
|
41
|
+
annotations?: {
|
|
42
|
+
streamingHint?: boolean;
|
|
43
|
+
} & {
|
|
44
|
+
destructiveHint?: boolean;
|
|
45
|
+
idempotentHint?: boolean;
|
|
46
|
+
openWorldHint?: boolean;
|
|
47
|
+
readOnlyHint?: boolean;
|
|
48
|
+
title?: string;
|
|
49
|
+
};
|
|
50
|
+
canAccess?: (auth: T) => boolean;
|
|
51
|
+
description?: string;
|
|
52
|
+
execute: (args: ToolParameters.InferOutput<TParams>, context?: any) => Promise<any>;
|
|
53
|
+
name?: string;
|
|
54
|
+
inputSchema?: TParams;
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface FastMCPTool<T extends Record<string, unknown> | undefined = any, TParams extends ToolParameters = ToolParameters> extends AITool<T, TParams> {
|
|
58
|
+
parameters?: TParams;
|
|
59
|
+
name: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Type for a collection of AI tools with preserved schema types
|
|
63
|
+
* @template T - Record mapping tool names to their inputSchema types
|
|
64
|
+
* @example AITools<{getUserById: z.object({id: z.string()}), createUser: z.object({name: z.string()})}>
|
|
65
|
+
*/
|
|
66
|
+
export type AITools<T extends Record<string, ToolParameters> = Record<string, z.ZodSchema>> = {
|
|
67
|
+
[K in keyof T]: AITool<any, T[K]>;
|
|
68
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AITools, FastMCPTool, ToolParameters } from "./schemas/schemas_tool_config";
|
|
2
|
+
/**
|
|
3
|
+
* FastMCP-compatible interface for MCP server functionality
|
|
4
|
+
* Provides exact API compatibility with FastMCP.addTool method
|
|
5
|
+
*/
|
|
6
|
+
export interface FastMCPCompatible {
|
|
7
|
+
addTool<Params extends ToolParameters>(tool: FastMCPTool<any, Params>): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* ModalityFastMCP - A FastMCP-compatible implementation
|
|
11
|
+
* Provides addTool and getTools functionality for managing MCP tools
|
|
12
|
+
*/
|
|
13
|
+
export declare class ModalityFastMCP implements FastMCPCompatible {
|
|
14
|
+
private tools;
|
|
15
|
+
/**
|
|
16
|
+
* Add a tool to the server
|
|
17
|
+
*/
|
|
18
|
+
addTool<Params extends ToolParameters>(tool: FastMCPTool<any, Params>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get all registered tools
|
|
21
|
+
*/
|
|
22
|
+
getTools(): FastMCPTool<any, any>[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Setup function that optionally registers AITools with MCP server
|
|
26
|
+
* Automatically infers and preserves schema types from the input
|
|
27
|
+
*/
|
|
28
|
+
export declare const setupAITools: <T extends Record<string, ToolParameters>>(aiTools: AITools<T>, mcpServer?: FastMCPCompatible) => AITools<T>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModalityFastMCP - A FastMCP-compatible implementation
|
|
3
|
+
* Provides addTool and getTools functionality for managing MCP tools
|
|
4
|
+
*/
|
|
5
|
+
export class ModalityFastMCP {
|
|
6
|
+
tools = new Map();
|
|
7
|
+
/**
|
|
8
|
+
* Add a tool to the server
|
|
9
|
+
*/
|
|
10
|
+
addTool(tool) {
|
|
11
|
+
this.tools.set(tool.name, tool);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get all registered tools
|
|
15
|
+
*/
|
|
16
|
+
getTools() {
|
|
17
|
+
return Array.from(this.tools.values());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Setup function that optionally registers AITools with MCP server
|
|
22
|
+
* Automatically infers and preserves schema types from the input
|
|
23
|
+
*/
|
|
24
|
+
export const setupAITools = (aiTools, mcpServer) => {
|
|
25
|
+
// Only register tools with MCP server if provided
|
|
26
|
+
if (mcpServer) {
|
|
27
|
+
Object.entries(aiTools).forEach(([toolName, aiTool]) => {
|
|
28
|
+
let name = null != aiTool.name ? aiTool.name : toolName;
|
|
29
|
+
const { inputSchema, ...restAITool } = aiTool; // Destructure to avoid unused variable warning
|
|
30
|
+
mcpServer.addTool({
|
|
31
|
+
...restAITool,
|
|
32
|
+
parameters: inputSchema,
|
|
33
|
+
name,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return aiTools;
|
|
38
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.0.1",
|
|
3
|
+
"name": "modality-mcp-kit",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/react-atomic/modality"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/react-atomic/modality/tree/main/modality-mcp-kit",
|
|
9
|
+
"description": "Modality MCP Kit - Schema conversion utilities for MCP tool development with multi-library support",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"mcp",
|
|
12
|
+
"mcp-toolkit",
|
|
13
|
+
"mcp-tools",
|
|
14
|
+
"model-context-protocol",
|
|
15
|
+
"json-schema",
|
|
16
|
+
"xsschema",
|
|
17
|
+
"schema-conversion",
|
|
18
|
+
"tool-parameters",
|
|
19
|
+
"zod",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"author": "Hill <hill@kimo.com>",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"xsschema": "0.3.5",
|
|
26
|
+
"zod": "^3.25.76",
|
|
27
|
+
"zod-to-json-schema": "^3.24.6"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/bun": "^1.2.22",
|
|
31
|
+
"typescript": "^5.9.2"
|
|
32
|
+
},
|
|
33
|
+
"exports": {
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"require": "./dist/index.js",
|
|
36
|
+
"import": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"types": "./dist/types/index.d.ts",
|
|
39
|
+
"main": "./dist/index.js",
|
|
40
|
+
"module": "./dist/index.js",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "bun tsc -p ./",
|
|
43
|
+
"build:types": "echo 'Starting build validation...' && bun --version && echo 'Running TypeScript type checking...' && bun tsc --noEmit --strict && echo '✅ Build validation successful - no TypeScript errors found' || (echo '❌ Build failed' && exit 1)",
|
|
44
|
+
"test": "bun test",
|
|
45
|
+
"prepublishOnly": "npm run build && npm run test"
|
|
46
|
+
},
|
|
47
|
+
"files": ["package.json", "README.md", "dist"]
|
|
48
|
+
}
|