feat: support Standard Schema for tool/prompt schemas (#1689)
Co-authored-by: Matt Carey <mcarey@cloudflare.com>
This commit is contained in:
parent
ccb78f2043
commit
0784be1a67
3 changed files with 1327 additions and 212 deletions
|
|
@ -34,14 +34,17 @@
|
|||
"dependencies": {
|
||||
"@hono/node-server": "catalog:runtimeServerOnly",
|
||||
"@modelcontextprotocol/examples-shared": "workspace:^",
|
||||
"@modelcontextprotocol/node": "workspace:^",
|
||||
"@modelcontextprotocol/server": "workspace:^",
|
||||
"@modelcontextprotocol/express": "workspace:^",
|
||||
"@modelcontextprotocol/hono": "workspace:^",
|
||||
"@modelcontextprotocol/node": "workspace:^",
|
||||
"@modelcontextprotocol/server": "workspace:^",
|
||||
"@valibot/to-json-schema": "catalog:devTools",
|
||||
"arktype": "catalog:devTools",
|
||||
"better-auth": "^1.4.17",
|
||||
"cors": "catalog:runtimeServerOnly",
|
||||
"express": "catalog:runtimeServerOnly",
|
||||
"hono": "catalog:runtimeServerOnly",
|
||||
"valibot": "catalog:devTools",
|
||||
"zod": "catalog:runtimeShared"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
28
examples/server/src/arktypeExample.ts
Normal file
28
examples/server/src/arktypeExample.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env node
|
||||
/**
|
||||
* Minimal MCP server using ArkType for schema validation.
|
||||
* ArkType implements the Standard Schema spec with built-in JSON Schema conversion.
|
||||
*/
|
||||
|
||||
import { McpServer, StdioServerTransport } from '@modelcontextprotocol/server';
|
||||
import { type } from 'arktype';
|
||||
|
||||
const server = new McpServer({
|
||||
name: 'arktype-example',
|
||||
version: '1.0.0'
|
||||
});
|
||||
|
||||
// Register a tool with ArkType schema
|
||||
server.registerTool(
|
||||
'greet',
|
||||
{
|
||||
description: 'Generate a greeting',
|
||||
inputSchema: type({ name: 'string' })
|
||||
},
|
||||
async ({ name }) => ({
|
||||
content: [{ type: 'text', text: `Hello, ${name}!` }]
|
||||
})
|
||||
);
|
||||
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
30
examples/server/src/valibotExample.ts
Normal file
30
examples/server/src/valibotExample.ts
Normal file
|
|
@ -0,0 +1,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);
|
||||
Loading…
Reference in a new issue