ai_code_review
Analyze source code to identify bugs, security vulnerabilities, and improvement opportunities while suggesting best practices for various programming languages.
Instructions
AI-powered code review. Returns bugs, improvements, security issues, and best practices. Cost: $0.05 USDC via x402.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The source code to review | |
| language | No | Programming language, e.g. 'typescript', 'python' |
Implementation Reference
- mcp-server/src/index.ts:224-224 (handler)Handler function for ai_code_review tool - calls the API endpoint /v1/ai/code-review with code and language parameters, formats and returns the response
async ({ code, language }) => formatResponse(await callApi("POST", "/v1/ai/code-review", { code, language })) - mcp-server/src/index.ts:220-223 (schema)Input schema for ai_code_review tool using Zod - defines 'code' as required string parameter and 'language' as optional string parameter
{ code: z.string().describe("The source code to review"), language: z.string().optional().describe("Programming language, e.g. 'typescript', 'python'"), }, - mcp-server/src/index.ts:217-225 (registration)Registration of ai_code_review tool with the MCP server - defines tool name, description, schema, and handler
server.tool( "ai_code_review", "AI-powered code review. Returns bugs, improvements, security issues, and best practices. Cost: $0.05 USDC via x402.", { code: z.string().describe("The source code to review"), language: z.string().optional().describe("Programming language, e.g. 'typescript', 'python'"), }, async ({ code, language }) => formatResponse(await callApi("POST", "/v1/ai/code-review", { code, language })) ); - mcp-server/src/index.ts:25-50 (helper)Helper function callApi - makes HTTP requests to the AsterPay API backend, handles payment required (402) responses
async function callApi( method: "GET" | "POST", path: string, body?: Record<string, unknown> ): Promise<{ status: number; data: unknown; paymentRequired?: unknown }> { const url = `${API_BASE}${path}`; const headers: Record<string, string> = { "Content-Type": "application/json" }; const res = await fetch(url, { method, headers, ...(body ? { body: JSON.stringify(body) } : {}), }); const data = await res.json(); if (res.status === 402) { return { status: 402, data: null, paymentRequired: data, }; } return { status: res.status, data }; } - mcp-server/src/index.ts:55-104 (helper)Helper function formatResponse - formats API responses for MCP tool output, handles payment required messages and normal responses
function formatResponse(result: { status: number; data: unknown; paymentRequired?: unknown }): { content: Array<{ type: "text"; text: string }>; } { if (result.status === 402) { const pr = result.paymentRequired as Record<string, unknown>; const accepts = (pr?.accepts as Array<Record<string, unknown>>)?.[0]; const amount = accepts?.amount ? `${(parseInt(accepts.amount as string) / 1e6).toFixed(6)} USDC` : "unknown"; const network = (accepts?.network as string) || "unknown"; return { content: [ { type: "text", text: [ "Payment required to access this endpoint.", "", `Amount: ${amount}`, `Network: ${network}`, `Asset: USDC`, `Pay to: ${(accepts?.payTo as string) || "unknown"}`, "", "To use this endpoint, send an x402 payment via @x402/fetch or the AsterPay SDK.", "Install: npm install @x402/fetch", "", "Example:", "```", 'import { wrapFetch } from "@x402/fetch";', 'const fetchWithPay = wrapFetch(fetch, wallet);', `const res = await fetchWithPay("${API_BASE}${(pr?.resource as Record<string, unknown>)?.url || ""}");`, "```", "", "Docs: https://x402-api-production-ba87.up.railway.app/docs", "Discovery: https://x402-api-production-ba87.up.railway.app/discovery/resources", ].join("\n"), }, ], }; } return { content: [ { type: "text", text: JSON.stringify(result.data, null, 2), }, ], }; }