|
1 | 1 | import type { Server } from '@modelcontextprotocol/sdk/server/index.js'; |
2 | 2 | import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js'; |
3 | | -import type { Notification, Prompt, Request } from '@modelcontextprotocol/sdk/types.js'; |
| 3 | +import type { Notification, Prompt, Request, ToolSchema } from '@modelcontextprotocol/sdk/types.js'; |
4 | 4 | import type { ValidateFunction } from 'ajv'; |
5 | 5 | import type { ActorDefaultRunOptions, ActorDefinition, ActorStoreList, PricingInfo } from 'apify-client'; |
6 | 6 |
|
7 | 7 | import type { ACTOR_PRICING_MODEL } from './const.js'; |
8 | 8 | import type { ActorsMcpServer } from './mcp/server.js'; |
9 | 9 | import type { toolCategories } from './tools/index.js'; |
10 | 10 | import type { ProgressTracker } from './utils/progress.js'; |
| 11 | +import z from 'zod'; |
11 | 12 |
|
12 | 13 | export interface ISchemaProperties { |
13 | 14 | type: string; |
@@ -60,19 +61,22 @@ export type ActorDefinitionPruned = Pick<ActorDefinitionWithDesc, |
60 | 61 |
|
61 | 62 | /** |
62 | 63 | * Base interface for all tools in the MCP server. |
63 | | - * Contains common properties shared by all tool types. |
| 64 | + * Extends the MCP SDK's Tool schema, which requires inputSchema to have type: "object". |
| 65 | + * Adds ajvValidate for runtime validation. |
64 | 66 | */ |
65 | | -export interface ToolBase { |
66 | | - /** Unique name/identifier for the tool */ |
67 | | - name: string; |
68 | | - /** Description of what the tool does */ |
69 | | - description: string; |
70 | | - /** JSON schema defining the tool's input parameters */ |
71 | | - inputSchema: object; |
| 67 | +export interface ToolBase extends z.infer<typeof ToolSchema> { |
72 | 68 | /** AJV validation function for the input schema */ |
73 | 69 | ajvValidate: ValidateFunction; |
74 | 70 | } |
75 | 71 |
|
| 72 | +/** |
| 73 | + * Type for MCP SDK's inputSchema constraint. |
| 74 | + * Extracted directly from the MCP SDK's ToolSchema to ensure alignment with the specification. |
| 75 | + * The MCP SDK requires inputSchema to have type: "object" (literal) at the top level. |
| 76 | + * Use this type when casting schemas that have type: string to the strict MCP format. |
| 77 | + */ |
| 78 | +export type McpInputSchema = z.infer<typeof ToolSchema>['inputSchema']; |
| 79 | + |
76 | 80 | /** |
77 | 81 | * Interface for Actor-based tools - tools that wrap Apify Actors. |
78 | 82 | * Extends ToolBase with Actor-specific properties. |
|
0 commit comments