|
1 | 1 | import { z } from 'zod'; |
2 | 2 |
|
3 | | -import { ApifyClient } from '../apify-client.js'; |
4 | 3 | import { HelperTools, TOOL_STATUS } from '../const.js'; |
5 | 4 | import type { InternalToolArgs, ToolEntry, ToolInputSchema } from '../types.js'; |
6 | 5 | import { compileSchema } from '../utils/ajv.js'; |
7 | 6 | import { parseCommaSeparatedList } from '../utils/generic.js'; |
8 | 7 | import { buildMCPResponse } from '../utils/mcp.js'; |
9 | 8 | import { generateSchemaFromItems } from '../utils/schema-generation.js'; |
| 9 | +import { createApifyClientWithSkyfireSupport, validateSkyfirePayId } from '../utils/skyfire.js'; |
10 | 10 |
|
11 | 11 | const getDatasetArgs = z.object({ |
12 | 12 | datasetId: z.string() |
@@ -56,17 +56,24 @@ USAGE EXAMPLES: |
56 | 56 | - user_input: Show info for dataset xyz123 |
57 | 57 | - user_input: What fields does username~my-dataset have?`, |
58 | 58 | inputSchema: z.toJSONSchema(getDatasetArgs) as ToolInputSchema, |
59 | | - ajvValidate: compileSchema(z.toJSONSchema(getDatasetArgs)), |
| 59 | + /** |
| 60 | + * Allow additional properties for Skyfire mode to pass `skyfire-pay-id`. |
| 61 | + */ |
| 62 | + ajvValidate: compileSchema({ ...z.toJSONSchema(getDatasetArgs), additionalProperties: true }), |
60 | 63 | annotations: { |
61 | 64 | title: 'Get dataset', |
62 | 65 | readOnlyHint: true, |
63 | 66 | idempotentHint: true, |
64 | 67 | openWorldHint: false, |
65 | 68 | }, |
66 | 69 | call: async (toolArgs: InternalToolArgs) => { |
67 | | - const { args, apifyToken } = toolArgs; |
| 70 | + const { args, apifyToken, apifyMcpServer } = toolArgs; |
68 | 71 | const parsed = getDatasetArgs.parse(args); |
69 | | - const client = new ApifyClient({ token: apifyToken }); |
| 72 | + |
| 73 | + const skyfireError = validateSkyfirePayId(apifyMcpServer, args); |
| 74 | + if (skyfireError) return skyfireError; |
| 75 | + |
| 76 | + const client = createApifyClientWithSkyfireSupport(apifyMcpServer, args, apifyToken); |
70 | 77 | const v = await client.dataset(parsed.datasetId).get(); |
71 | 78 | if (!v) { |
72 | 79 | return buildMCPResponse({ |
@@ -98,17 +105,24 @@ USAGE EXAMPLES: |
98 | 105 | - user_input: Get first 100 items from dataset abd123 |
99 | 106 | - user_input: Get only metadata.url and title from dataset username~my-dataset (flatten metadata)`, |
100 | 107 | inputSchema: z.toJSONSchema(getDatasetItemsArgs) as ToolInputSchema, |
101 | | - ajvValidate: compileSchema(z.toJSONSchema(getDatasetItemsArgs)), |
| 108 | + /** |
| 109 | + * Allow additional properties for Skyfire mode to pass `skyfire-pay-id`. |
| 110 | + */ |
| 111 | + ajvValidate: compileSchema({ ...z.toJSONSchema(getDatasetItemsArgs), additionalProperties: true }), |
102 | 112 | annotations: { |
103 | 113 | title: 'Get dataset items', |
104 | 114 | readOnlyHint: true, |
105 | 115 | idempotentHint: true, |
106 | 116 | openWorldHint: false, |
107 | 117 | }, |
108 | 118 | call: async (toolArgs: InternalToolArgs) => { |
109 | | - const { args, apifyToken } = toolArgs; |
| 119 | + const { args, apifyToken, apifyMcpServer } = toolArgs; |
110 | 120 | const parsed = getDatasetItemsArgs.parse(args); |
111 | | - const client = new ApifyClient({ token: apifyToken }); |
| 121 | + |
| 122 | + const skyfireError = validateSkyfirePayId(apifyMcpServer, args); |
| 123 | + if (skyfireError) return skyfireError; |
| 124 | + |
| 125 | + const client = createApifyClientWithSkyfireSupport(apifyMcpServer, args, apifyToken); |
112 | 126 |
|
113 | 127 | // Convert comma-separated strings to arrays |
114 | 128 | const fields = parseCommaSeparatedList(parsed.fields); |
@@ -167,17 +181,24 @@ USAGE EXAMPLES: |
167 | 181 | - user_input: Generate schema for dataset 34das2 using 10 items |
168 | 182 | - user_input: Show schema of username~my-dataset (clean items only)`, |
169 | 183 | inputSchema: z.toJSONSchema(getDatasetSchemaArgs) as ToolInputSchema, |
170 | | - ajvValidate: compileSchema(z.toJSONSchema(getDatasetSchemaArgs)), |
| 184 | + /** |
| 185 | + * Allow additional properties for Skyfire mode to pass `skyfire-pay-id`. |
| 186 | + */ |
| 187 | + ajvValidate: compileSchema({ ...z.toJSONSchema(getDatasetSchemaArgs), additionalProperties: true }), |
171 | 188 | annotations: { |
172 | 189 | title: 'Get dataset schema', |
173 | 190 | readOnlyHint: true, |
174 | 191 | idempotentHint: true, |
175 | 192 | openWorldHint: false, |
176 | 193 | }, |
177 | 194 | call: async (toolArgs: InternalToolArgs) => { |
178 | | - const { args, apifyToken } = toolArgs; |
| 195 | + const { args, apifyToken, apifyMcpServer } = toolArgs; |
179 | 196 | const parsed = getDatasetSchemaArgs.parse(args); |
180 | | - const client = new ApifyClient({ token: apifyToken }); |
| 197 | + |
| 198 | + const skyfireError = validateSkyfirePayId(apifyMcpServer, args); |
| 199 | + if (skyfireError) return skyfireError; |
| 200 | + |
| 201 | + const client = createApifyClientWithSkyfireSupport(apifyMcpServer, args, apifyToken); |
181 | 202 |
|
182 | 203 | // Get dataset items |
183 | 204 | const datasetResponse = await client.dataset(parsed.datasetId).listItems({ |
|
0 commit comments