execute_service
Run AgentDesk marketplace services including AI code reviews, web scraping, and PDF generation by passing custom parameters through authenticated API requests.
Instructions
Execute a service on the AgentDesk marketplace. Requires an AgentDesk API key for authentication. Pass service-specific input parameters.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| service_id | Yes | Service ID to execute (e.g., "review", "web_scrape", "realtime_jp", "pdf_generate", "summarize", "classify") | |
| input | Yes | Service-specific input parameters | |
| api_key | No | BYOK: Your Anthropic API key (for AI-powered services like review) |
Implementation Reference
- src/index.ts:115-147 (registration)Registration of the 'execute_service' tool with the MCP server, including name, description, and Zod input schema
server.tool( 'execute_service', 'Execute a service on the AgentDesk marketplace. Requires an AgentDesk API key for authentication. Pass service-specific input parameters.', { service_id: z.string().describe('Service ID to execute (e.g., "review", "web_scrape", "realtime_jp", "pdf_generate", "summarize", "classify")'), input: z.record(z.unknown()).describe('Service-specific input parameters'), api_key: z.string().optional().describe('BYOK: Your Anthropic API key (for AI-powered services like review)'), }, safeAsyncTool(async ({ service_id, input, api_key }) => { const agentdeskKey = process.env.AGENTDESK_API_KEY if (!agentdeskKey) { throw new Error('AGENTDESK_API_KEY environment variable is required for service execution.') } const body: Record<string, unknown> = { input } if (api_key) body.api_key = api_key const res = await fetch(`${AGENTDESK_API}/api/v1/services/${encodeURIComponent(service_id)}/execute`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${agentdeskKey}`, }, body: JSON.stringify(body), }) if (!res.ok) { const errorBody = await res.text() throw new Error(`API error ${res.status}: ${errorBody}`) } return await res.json() }) ) - src/index.ts:123-147 (handler)Handler function that executes the service via HTTP POST to AgentDesk API with authentication using AGENTDESK_API_KEY
safeAsyncTool(async ({ service_id, input, api_key }) => { const agentdeskKey = process.env.AGENTDESK_API_KEY if (!agentdeskKey) { throw new Error('AGENTDESK_API_KEY environment variable is required for service execution.') } const body: Record<string, unknown> = { input } if (api_key) body.api_key = api_key const res = await fetch(`${AGENTDESK_API}/api/v1/services/${encodeURIComponent(service_id)}/execute`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${agentdeskKey}`, }, body: JSON.stringify(body), }) if (!res.ok) { const errorBody = await res.text() throw new Error(`API error ${res.status}: ${errorBody}`) } return await res.json() }) ) - src/index.ts:118-122 (schema)Zod schema defining input parameters for execute_service: service_id (string), input (record), and api_key (optional string)
{ service_id: z.string().describe('Service ID to execute (e.g., "review", "web_scrape", "realtime_jp", "pdf_generate", "summarize", "classify")'), input: z.record(z.unknown()).describe('Service-specific input parameters'), api_key: z.string().optional().describe('BYOK: Your Anthropic API key (for AI-powered services like review)'), }, - src/index.ts:22-38 (helper)safeAsyncTool helper function that wraps async tool handlers for MCP-compliant error handling, converting results to text content
function safeAsyncTool<T>( fn: (args: T) => Promise<string | object> ): (args: T) => Promise<{ content: { type: 'text'; text: string }[]; isError?: boolean }> { return async (args: T) => { try { const result = await fn(args) const text = typeof result === 'string' ? result : JSON.stringify(result, null, 2) return { content: [{ type: 'text' as const, text }] } } catch (e) { const message = e instanceof Error ? e.message : String(e) return { content: [{ type: 'text' as const, text: `Error: ${message}` }], isError: true, } } } }