Skip to main content
Glama
KasarLabs
by KasarLabs

assist_with_cairo

Generate and analyze Cairo code for Starknet smart contracts, including writing, refactoring, and completing specific implementations using AI-powered assistance.

Instructions

Provides assistance with Cairo and Starknet development tasks through AI-powered analysis.

Call this tool when the user's request involves writing, refactoring, implementing from scratch, or completing specific parts (like TODOs) of Cairo code or smart contracts.

The tool analyzes the query and context against Cairo/Starknet best practices and documentation, returning helpful information to generate accurate code or explanations.

This tool should also be called to get a better understanding of Starknet's ecosystem, features, and capacities.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe user's question regarding Cairo and Starknet development. Try to be as specific as possible for better results (e.g., 'Using OpenZeppelin to build an ERC20' rather than just 'ERC20').
codeSnippetsNoOptional: Code snippets for context. This will help the tool understand the user's intent and provide more accurate answers. Provide as much relevant code as possible to fit the user's request.
historyNoOptional: The preceding conversation history. This can help the tool understand the context of the discussion and provide more accurate answers.

Implementation Reference

  • The primary handler function that executes the logic for the 'assist_with_cairo' tool. It constructs a contextual message from query, code snippets, and history, sends it to the Cairo Coder API, and returns the assistant's response or error.
    private async handleCairoAssistance(args: {
      query: string;
      codeSnippets?: string[];
      history?: string[];
    }) {
      try {
        const { query, codeSnippets, history } = args;
    
        if (!query) {
          throw new Error("Query parameter is required");
        }
    
        let contextualMessage = query;
    
        if (codeSnippets && codeSnippets.length > 0) {
          contextualMessage += `\n\nCode snippets for context:\n${codeSnippets.join("\n\n")}`;
        }
    
        if (history && history.length > 0) {
          contextualMessage = `Previous conversation context:\n${history.join("\n")}\n\nCurrent query: ${contextualMessage}`;
        }
    
        const requestBody: CairoCoderRequest = {
          messages: [
            {
              role: "user",
              content: contextualMessage,
            },
          ],
        };
    
        // Prepare headers based on mode
        const headers: Record<string, string> = {
          "Content-Type": "application/json",
          mcp: "true",
        };
    
        // Only add API key header in public API mode
        if (!this.isLocalMode && this.apiKey) {
          headers["x-api-key"] = this.apiKey;
        }
    
        const response = await fetch(this.apiUrl, {
          method: "POST",
          headers,
          body: JSON.stringify(requestBody),
        });
    
        if (!response.ok) {
          const errorText = await response.text();
          throw new Error(
            `API request failed: ${response.status} ${response.statusText} - ${errorText}`,
          );
        }
    
        const data = (await response.json()) as CairoCoderResponse;
    
        if (!data.choices || data.choices.length === 0) {
          throw new Error("No response received from Cairo Coder API");
        }
    
        const assistantResponse = data.choices[0].message.content;
    
        return {
          content: [
            {
              type: "text",
              text: assistantResponse,
            },
          ],
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : "Unknown error occurred";
    
        return {
          content: [
            {
              type: "text",
              text: `Error: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
    }
  • src/index.ts:143-157 (registration)
    Registers the CallToolRequestSchema handler, which dispatches calls to 'assist_with_cairo' to the specific handler function.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args } = request.params;
    
      if (name === "assist_with_cairo") {
        return await this.handleCairoAssistance(
          args as {
            query: string;
            codeSnippets?: string[];
            history?: string[];
          },
        );
      }
    
      throw new Error(`Unknown tool: ${name}`);
    });
  • src/index.ts:99-141 (registration)
    Registers the ListToolsRequestSchema handler that provides the definition and schema for the 'assist_with_cairo' tool.
      this.server.setRequestHandler(ListToolsRequestSchema, async () => {
        return {
          tools: [
            {
              name: "assist_with_cairo",
              description: `Provides assistance with Cairo and Starknet development tasks through AI-powered analysis.
    
    Call this tool when the user's request involves **writing, refactoring, implementing from scratch, or completing specific parts (like TODOs)** of Cairo code or smart contracts.
    
    The tool analyzes the query and context against Cairo/Starknet best practices and documentation, returning helpful information to generate accurate code or explanations.
    
    This tool should also be called to get a better understanding of Starknet's ecosystem, features, and capacities.`,
              inputSchema: {
                type: "object",
                properties: {
                  query: {
                    type: "string",
                    description:
                      "The user's question regarding Cairo and Starknet development. Try to be as specific as possible for better results (e.g., 'Using OpenZeppelin to build an ERC20' rather than just 'ERC20').",
                  },
                  codeSnippets: {
                    type: "array",
                    items: {
                      type: "string",
                    },
                    description:
                      "Optional: Code snippets for context. This will help the tool understand the user's intent and provide more accurate answers. Provide as much relevant code as possible to fit the user's request.",
                  },
                  history: {
                    type: "array",
                    items: {
                      type: "string",
                    },
                    description:
                      "Optional: The preceding conversation history. This can help the tool understand the context of the discussion and provide more accurate answers.",
                  },
                },
                required: ["query"],
              },
            } as Tool,
          ],
        };
      });
  • Input schema definition specifying the parameters for the 'assist_with_cairo' tool.
    inputSchema: {
      type: "object",
      properties: {
        query: {
          type: "string",
          description:
            "The user's question regarding Cairo and Starknet development. Try to be as specific as possible for better results (e.g., 'Using OpenZeppelin to build an ERC20' rather than just 'ERC20').",
        },
        codeSnippets: {
          type: "array",
          items: {
            type: "string",
          },
          description:
            "Optional: Code snippets for context. This will help the tool understand the user's intent and provide more accurate answers. Provide as much relevant code as possible to fit the user's request.",
        },
        history: {
          type: "array",
          items: {
            type: "string",
          },
          description:
            "Optional: The preceding conversation history. This can help the tool understand the context of the discussion and provide more accurate answers.",
        },
      },
      required: ["query"],
    },
Behavior3/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes the tool's function ('AI-powered analysis') and output ('returning helpful information to generate accurate code or explanations'), which covers basic behavior. However, it lacks details on limitations, error handling, or performance characteristics (e.g., response time, accuracy constraints), which would be valuable for an AI agent to know when invoking this tool.

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 and front-loaded, with the core purpose stated first. Each sentence adds value: the first defines the tool, the second provides usage guidelines, the third explains the analysis process, and the fourth adds an extra use case. While efficient, the final sentence could be integrated more seamlessly, and there's minor repetition (e.g., 'accurate' appears twice), preventing a perfect score.

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

Completeness3/5

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

Given the complexity of the tool (AI-powered analysis with 3 parameters) and the absence of both annotations and an output schema, the description is moderately complete. It covers purpose and usage well but lacks details on behavioral traits (e.g., how the AI analysis works, potential limitations) and output format. Without an output schema, the description should ideally hint at what the tool returns, but it only vaguely mentions 'helpful information,' leaving gaps for an AI agent to understand the full context.

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?

The schema description coverage is 100%, meaning all parameters are well-documented in the input schema itself. The description does not add any additional meaning or context about the parameters beyond what the schema provides (e.g., it doesn't explain how 'query' interacts with 'codeSnippets' or 'history' in practice). According to the rules, when schema coverage is high (>80%), the baseline score is 3 even without parameter info in the description.

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

Purpose4/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: 'Provides assistance with Cairo and Starknet development tasks through AI-powered analysis.' It specifies the verb ('assists with') and resource ('Cairo and Starknet development tasks'), making it easy to understand what the tool does. However, since there are no sibling tools mentioned, it cannot differentiate from alternatives, preventing a perfect score of 5.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use the tool: 'Call this tool when the user's request involves **writing, refactoring, implementing from scratch, or completing specific parts (like TODOs)** of Cairo code or smart contracts.' It also includes additional use cases like understanding Starknet's ecosystem. This comprehensive guidance leaves no ambiguity about appropriate usage scenarios.

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/KasarLabs/cairo-coder-mcp'

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