| 175 | } |
| 176 | |
| 177 | async handle(params: Record<string, unknown>): Promise<CallToolResult> { |
| 178 | if (this.disabledReason) { |
| 179 | return { |
| 180 | content: [ |
| 181 | { |
| 182 | type: 'text', |
| 183 | text: this.disabledReason, |
| 184 | }, |
| 185 | ], |
| 186 | isError: true, |
| 187 | }; |
| 188 | } |
| 189 | |
| 190 | const unknownArgumentNames = this.unknownArgumentNames(params); |
| 191 | if (unknownArgumentNames.length) { |
| 192 | return { |
| 193 | content: [ |
| 194 | { |
| 195 | type: 'text', |
| 196 | text: buildUnknownArgumentsMessage( |
| 197 | this.tool.name, |
| 198 | unknownArgumentNames, |
| 199 | Object.keys(this.inputSchema), |
| 200 | ), |
| 201 | }, |
| 202 | ], |
| 203 | isError: true, |
| 204 | }; |
| 205 | } |
| 206 | |
| 207 | const guard = await this.toolMutex.acquire(); |
| 208 | const startTime = Date.now(); |
| 209 | let success = false; |
| 210 | try { |
| 211 | logger?.( |
| 212 | `${this.tool.name} request: ${JSON.stringify(params, null, ' ')}`, |
| 213 | ); |
| 214 | const context = await this.getContext(); |
| 215 | logger?.(`${this.tool.name} context: resolved`); |
| 216 | await context.detectOpenDevToolsWindows(); |
| 217 | const response = this.serverArgs.slim |
| 218 | ? new SlimMcpResponse(this.serverArgs) |
| 219 | : new McpResponse(this.serverArgs); |
| 220 | |
| 221 | response.setRedactNetworkHeaders(this.serverArgs.redactNetworkHeaders); |
| 222 | try { |
| 223 | if (this.tool.verifyFilesSchema) { |
| 224 | for (const key of this.tool.verifyFilesSchema) { |
| 225 | const filePath = params[key]; |
| 226 | await context.validatePath(filePath as string); |
| 227 | } |
| 228 | } |
| 229 | if (isPageScopedTool(this.tool)) { |
| 230 | const pageId = |
| 231 | typeof params.pageId === 'number' ? params.pageId : undefined; |
| 232 | const page = |
| 233 | this.serverArgs.experimentalPageIdRouting && |
| 234 | pageId !== undefined && |