forked from modelcontextprotocol/typescript-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalibotExample.ts
More file actions
30 lines (26 loc) · 843 Bytes
/
valibotExample.ts
File metadata and controls
30 lines (26 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env node
/**
* Minimal MCP server using Valibot for schema validation.
* Use toStandardJsonSchema() from @valibot/to-json-schema to create
* StandardJSONSchemaV1-compliant schemas.
*/
import { McpServer, StdioServerTransport } from '@modelcontextprotocol/server';
import { toStandardJsonSchema } from '@valibot/to-json-schema';
import * as v from 'valibot';
const server = new McpServer({
name: 'valibot-example',
version: '1.0.0'
});
// Register a tool with Valibot schema
server.registerTool(
'greet',
{
description: 'Generate a greeting',
inputSchema: toStandardJsonSchema(v.object({ name: v.string() }))
},
async ({ name }) => ({
content: [{ type: 'text', text: `Hello, ${name}!` }]
})
);
const transport = new StdioServerTransport();
await server.connect(transport);