chore: steer towards mcp types a bit (#880)

This commit is contained in:
Pavel Feldman
2025-08-13 14:09:37 -07:00
committed by GitHub
parent 8572ab300c
commit 73adb0fdf0
10 changed files with 87 additions and 141 deletions

View File

@@ -22,7 +22,7 @@ import { Response } from './response.js';
import { SessionLog } from './sessionLog.js';
import { filteredTools } from './tools.js';
import { packageJSON } from './utils/package.js';
import { toToolDefinition } from './tools/tool.js';
import { toMcpTool } from './tools/tool.js';
import type { Tool } from './tools/tool.js';
import type { BrowserContextFactory } from './browserContextFactory.js';
@@ -64,12 +64,14 @@ export class BrowserServerBackend implements ServerBackend {
});
}
tools(): mcpServer.ToolDefinition[] {
return this._tools.map(tool => toToolDefinition(tool.schema));
async listTools(): Promise<mcpServer.Tool[]> {
return this._tools.map(tool => toMcpTool(tool.schema));
}
async callTool(name: string, rawArguments: any) {
async callTool(name: string, rawArguments: mcpServer.CallToolRequest['params']['arguments']) {
const tool = this._tools.find(tool => tool.schema.name === name)!;
if (!tool)
throw new Error(`Tool "${name}" not found`);
const parsedArguments = tool.schema.inputSchema.parse(rawArguments || {});
const context = this._context!;
const response = new Response(context, name, parsedArguments);