Skip to main content
Glama
timolein74

asterpay-mcp-server

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
NameRequiredDescriptionDefault
codeYesThe source code to review
languageNoProgramming language, e.g. 'typescript', 'python'

Implementation Reference

  • 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 }))
  • 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'"),
    },
  • 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 }))
    );
  • 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 };
    }
  • 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),
          },
        ],
      };
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the cost, which is useful context, but lacks details on rate limits, error handling, or what the output looks like (e.g., format of bugs and improvements). It does not contradict annotations, but could be more informative for a tool with potential behavioral complexities.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with two sentences: one stating the purpose and one noting the cost. It is front-loaded with the main function, but the cost detail, while relevant, could be integrated more seamlessly. Overall, it is efficient with minimal waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of code review (which may involve detailed outputs) and no output schema, the description is incomplete. It lists what the tool returns but does not explain the format or structure of the output. With no annotations and incomplete behavioral context, it falls short for effective agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('code' and 'language'). The description does not add meaning beyond what the schema provides, such as examples or constraints. Baseline is 3 when schema does the heavy lifting, but no extra value is added.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('AI-powered code review') and resources ('code'), and it distinguishes from siblings by focusing on code analysis rather than sentiment, translation, or other unrelated tasks. The mention of 'bugs, improvements, security issues, and best practices' adds specificity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions a cost ('$0.05 USDC via x402'), which could imply a usage consideration, but does not specify prerequisites, limitations, or comparisons with other tools like 'ai_sentiment' or 'ai_summarize' for code-related tasks.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/timolein74/asterpay-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server