diff --git a/src/index.ts b/src/index.ts index dace44f..96b982a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,10 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { AgentDispatchError, type DispatchRequest, type RuntimeProfile, type RuntimeService } from "@agent-dispatch/core"; +import packageJson from "../package.json" with { type: "json" }; import { mcpToolSchemas } from "./schemas.js"; export function createAgentDispatchMcpServer(runtime: RuntimeService): McpServer { - const server = new McpServer({ name: "agentdispatch", version: "0.1.0" }); + const server = new McpServer({ name: "agentdispatch", version: packageJson.version }); server.tool("list_providers", mcpToolSchemas.list_providers.shape, async () => jsonContent(runtime.listProviders())); diff --git a/src/schemas.ts b/src/schemas.ts index 6e4d790..2e74a9c 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -39,8 +39,8 @@ export const taskIdInputSchema = z.object({ export const getTaskLogsInputSchema = z.object({ task_id: z.string(), - cursor: z.number().optional(), - limit: z.number().optional() + cursor: z.number().int().nonnegative().optional(), + limit: z.number().int().positive().max(64_000).optional() }); export const mcpToolSchemas = { diff --git a/test/schemas.test.ts b/test/schemas.test.ts index 06fc7c6..e468375 100644 --- a/test/schemas.test.ts +++ b/test/schemas.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { dispatchTaskInputSchema, mcpToolSchemas, spawnCloudAgentInputSchema } from "../src/index.js"; +import { dispatchTaskInputSchema, getTaskLogsInputSchema, mcpToolSchemas, spawnCloudAgentInputSchema } from "../src/index.js"; describe("MCP schemas", () => { it("keeps dispatch_task provider-neutral", () => { @@ -49,4 +49,16 @@ describe("MCP schemas", () => { runtime_tools: { enabled: ["web-search"] } }); }); + + it("constrains get_task_logs cursor and limit", () => { + expect(getTaskLogsInputSchema.parse({ task_id: "task_1", cursor: 0, limit: 64_000 })).toMatchObject({ + task_id: "task_1", + cursor: 0, + limit: 64_000 + }); + expect(() => getTaskLogsInputSchema.parse({ task_id: "task_1", cursor: -1 })).toThrow(); + expect(() => getTaskLogsInputSchema.parse({ task_id: "task_1", cursor: 1.5 })).toThrow(); + expect(() => getTaskLogsInputSchema.parse({ task_id: "task_1", limit: 0 })).toThrow(); + expect(() => getTaskLogsInputSchema.parse({ task_id: "task_1", limit: 64_001 })).toThrow(); + }); });