mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 06:57:33 +08:00
feat: MCP message type
This commit is contained in:
61
app/mcp/types.ts
Normal file
61
app/mcp/types.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
// ref: https://spec.modelcontextprotocol.io/specification/basic/messages/
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
export interface McpRequestMessage {
|
||||
jsonrpc?: "2.0";
|
||||
id?: string | number;
|
||||
method: "tools/call" | string;
|
||||
params?: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
}
|
||||
|
||||
export const McpRequestMessageSchema: z.ZodType<McpRequestMessage> = z.object({
|
||||
jsonrpc: z.literal("2.0").optional(),
|
||||
id: z.union([z.string(), z.number()]).optional(),
|
||||
method: z.string(),
|
||||
params: z.record(z.unknown()).optional(),
|
||||
});
|
||||
|
||||
export interface McpResponseMessage {
|
||||
jsonrpc?: "2.0";
|
||||
id?: string | number;
|
||||
result?: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
error?: {
|
||||
code: number;
|
||||
message: string;
|
||||
data?: unknown;
|
||||
};
|
||||
}
|
||||
|
||||
export const McpResponseMessageSchema: z.ZodType<McpResponseMessage> = z.object(
|
||||
{
|
||||
jsonrpc: z.literal("2.0").optional(),
|
||||
id: z.union([z.string(), z.number()]).optional(),
|
||||
result: z.record(z.unknown()).optional(),
|
||||
error: z
|
||||
.object({
|
||||
code: z.number(),
|
||||
message: z.string(),
|
||||
data: z.unknown().optional(),
|
||||
})
|
||||
.optional(),
|
||||
},
|
||||
);
|
||||
|
||||
export interface McpNotifications {
|
||||
jsonrpc?: "2.0";
|
||||
method: string;
|
||||
params?: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
}
|
||||
|
||||
export const McpNotificationsSchema: z.ZodType<McpNotifications> = z.object({
|
||||
jsonrpc: z.literal("2.0").optional(),
|
||||
method: z.string(),
|
||||
params: z.record(z.unknown()).optional(),
|
||||
});
|
Reference in New Issue
Block a user