Schema conversion and tool registration utilities for Model Context Protocol (MCP) server development with multi-library support (Zod, Valibot, ArkType, Effect, Sury)
A comprehensive toolkit for building Model Context Protocol (MCP) servers with universal schema conversion and type-safe tool registration. Supports multiple validation libraries (Zod, Valibot, ArkType, Effect, Sury) and provides seamless FastMCP integration.
This skill helps you build MCP servers by providing schema conversion utilities and tool registration helpers. It converts validation schemas from popular libraries to JSON Schema format and transforms AITool definitions into FastMCP-compatible tools.
Install the modality-mcp-kit package:
```bash
npm install modality-mcp-kit
bun add modality-mcp-kit
```
Convert schemas from any supported validation library to JSON Schema:
**Supported Libraries:**
**Example:**
```typescript
import { toJsonSchema } from "modality-mcp-kit";
import { z } from "zod";
const userSchema = z.object({
id: z.string(),
name: z.string(),
age: z.number(),
email: z.string().email().optional()
});
const jsonSchema = toJsonSchema(userSchema);
// Returns standard JSON Schema object
```
Transform AITool definitions to FastMCP-compatible format with automatic schema conversion:
```typescript
import { setupAITools, ModalityFastMCP } from "modality-mcp-kit";
import { z } from "zod";
const mcp = new ModalityFastMCP();
const aiTools = {
getUserById: {
name: "get_user",
description: "Fetch user data by unique identifier",
inputSchema: z.object({
id: z.string().uuid()
}),
execute: async (args) => {
// Tool implementation
return { id: args.id, name: "John Doe" };
},
},
updateUser: {
name: "update_user",
description: "Update user information",
inputSchema: z.object({
id: z.string().uuid(),
name: z.string().min(1).optional(),
email: z.string().email().optional()
}),
execute: async (args) => {
// Update logic
return { success: true, updated: args };
},
}
};
// Registers all tools with the MCP server
setupAITools(aiTools, mcp);
```
Use the included ModalityFastMCP class for full MCP server functionality:
```typescript
import { ModalityFastMCP } from "modality-mcp-kit";
const server = new ModalityFastMCP();
// Add individual tools
server.addTool({
name: "search_docs",
description: "Search documentation by keyword",
parameters: {
type: "object",
properties: {
query: { type: "string" },
limit: { type: "number", default: 10 }
},
required: ["query"]
},
execute: async (args) => {
// Search implementation
return { results: [] };
}
});
// Retrieve all registered tools
const tools = server.getTools();
```
Choose your preferred validation library and define input schemas:
```typescript
import { z } from "zod";
// Example: File operation schema
const fileOperationSchema = z.object({
path: z.string(),
operation: z.enum(["read", "write", "delete"]),
content: z.string().optional()
});
```
Structure your tools with name, description, schema, and execution logic:
```typescript
const fileTools = {
readFile: {
name: "read_file",
description: "Read contents of a file",
inputSchema: z.object({ path: z.string() }),
execute: async ({ path }) => {
// Implementation
return { content: "file contents" };
}
},
writeFile: {
name: "write_file",
description: "Write content to a file",
inputSchema: z.object({
path: z.string(),
content: z.string()
}),
execute: async ({ path, content }) => {
// Implementation
return { success: true };
}
}
};
```
Create a FastMCP instance and register your tools:
```typescript
import { setupAITools, ModalityFastMCP } from "modality-mcp-kit";
const server = new ModalityFastMCP();
setupAITools(fileTools, server);
// Server is now ready with all tools registered
```
For standalone schema conversion without tool registration:
```typescript
import { toJsonSchema } from "modality-mcp-kit";
import { z } from "zod";
const configSchema = z.object({
apiKey: z.string(),
endpoint: z.string().url(),
timeout: z.number().positive().default(5000)
});
const jsonSchema = toJsonSchema(configSchema);
// Use jsonSchema for documentation, validation, or manual tool registration
```
**Parameters:**
**Returns:**
**Purpose:** Universal conversion from validation schemas to JSON Schema format.
**Parameters:**
**Behavior:**
**Returns:** Transformed tool definitions
**Methods:**
**Purpose:** FastMCP-compatible MCP server implementation.
```typescript
// Zod
import { z } from "zod";
const zodSchema = z.object({ id: z.string() });
// Valibot
import * as v from "valibot";
const valibotSchema = v.object({ id: v.string() });
// Both work with toJsonSchema
toJsonSchema(zodSchema);
toJsonSchema(valibotSchema);
```
```typescript
const advancedSchema = z.object({
user: z.object({
id: z.string().uuid(),
roles: z.array(z.enum(["admin", "user", "guest"])),
metadata: z.record(z.string(), z.unknown())
}),
timestamp: z.date().transform(d => d.toISOString())
});
const jsonSchema = toJsonSchema(advancedSchema);
```
```typescript
// Group related tools by domain
const databaseTools = { /* ... */ };
const fileSystemTools = { /* ... */ };
const apiTools = { /* ... */ };
const mcp = new ModalityFastMCP();
setupAITools(databaseTools, mcp);
setupAITools(fileSystemTools, mcp);
setupAITools(apiTools, mcp);
```
```typescript
import { setupAITools, ModalityFastMCP } from "modality-mcp-kit";
import { z } from "zod";
const mcp = new ModalityFastMCP();
const tools = {
calculateSum: {
name: "calculate_sum",
description: "Add two numbers together",
inputSchema: z.object({
a: z.number(),
b: z.number()
}),
execute: async ({ a, b }) => ({ result: a + b })
},
formatDate: {
name: "format_date",
description: "Format a date string",
inputSchema: z.object({
date: z.string(),
format: z.enum(["ISO", "US", "EU"]).default("ISO")
}),
execute: async ({ date, format }) => {
// Format logic
return { formatted: date };
}
}
};
setupAITools(tools, mcp);
// MCP server ready with two registered tools
console.log(mcp.getTools());
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/modality-mcp-kit/raw