Skip to main content
Glama

switch-chain

Change blockchain networks in MetaMask for MCPilot server, enabling AI to interact with different chains while maintaining wallet security.

Instructions

Switch the target chain

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainIdYes
addEthereumChainParameterNo

Implementation Reference

  • The main handler function that executes the chain switch using the wagmi switchChain function. It takes chainId and optional addEthereumChainParameter, calls switchChain, and returns the result as a text content block.
    execute: async (args) => {
      const chainId = args.chainId as typeof wagmiConfig['chains'][number]['id']
      const addEthereumChainParameter = args.addEthereumChainParameter
      const result = await switchChain(wagmiConfig, {
        chainId,
        addEthereumChainParameter,
      })
      return {
        content: [
          {
            type: "text",
            text: JSONStringify(result),
          },
        ],
      }
    },
  • Zod schema defining the input parameters for the switch-chain tool: required chainId (number) and optional addEthereumChainParameter object for adding a new chain.
    parameters: z.object({
      chainId: z.coerce.number(),
      addEthereumChainParameter: z.object({
        chainName: z.string(),
        nativeCurrency: z.object({
          name: z.string(),
          symbol: z.string(),
          decimals: z.coerce.number(),
        }).optional(),
        rpcUrls: z.string().array(),
        blockExplorerUrls: z.string().array().optional(),
        iconUrls: z.string().array().optional(),
      }).optional()
    }),
  • The registration function that adds the switch-chain tool to the FastMCP server, including name, description, schema, and handler.
    export function registerSwitchChainTools(server: FastMCP): void {
      server.addTool({
        name: "switch-chain",
        description: "Switch the target chain",
        parameters: z.object({
          chainId: z.coerce.number(),
          addEthereumChainParameter: z.object({
            chainName: z.string(),
            nativeCurrency: z.object({
              name: z.string(),
              symbol: z.string(),
              decimals: z.coerce.number(),
            }).optional(),
            rpcUrls: z.string().array(),
            blockExplorerUrls: z.string().array().optional(),
            iconUrls: z.string().array().optional(),
          }).optional()
        }),
        execute: async (args) => {
          const chainId = args.chainId as typeof wagmiConfig['chains'][number]['id']
          const addEthereumChainParameter = args.addEthereumChainParameter
          const result = await switchChain(wagmiConfig, {
            chainId,
            addEthereumChainParameter,
          })
          return {
            content: [
              {
                type: "text",
                text: JSONStringify(result),
              },
            ],
          }
        },
      });
    };
  • Top-level call to register the switch-chain tools during server initialization.
    registerSwitchChainTools(server);
Behavior1/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but offers none. It doesn't indicate whether this is a read-only or destructive operation, what permissions are required, whether it changes global state, what happens on success/failure, or any side effects. 'Switch' implies mutation but without any safety or behavioral context.

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

Conciseness3/5

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

The description is extremely concise (3 words) but this brevity comes at the cost of being under-specified rather than efficiently informative. While it's front-loaded with the core action, it lacks the necessary detail that would make it genuinely helpful. The structure is minimal but insufficient.

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

Completeness1/5

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

For a tool with 2 parameters (one complex nested object), no annotations, no output schema, and 0% schema description coverage, the description is completely inadequate. It doesn't explain what the tool does beyond the name, provides no parameter guidance, no behavioral context, and no usage instructions. This leaves the agent with insufficient information to use the tool correctly.

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

Parameters2/5

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

With 0% schema description coverage for both parameters (chainId and addEthereumChainParameter), the description provides zero information about what these parameters mean or how they should be used. The description doesn't mention parameters at all, leaving the agent to guess from the schema alone. This fails to compensate for the complete lack of schema documentation.

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

Purpose2/5

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

The description 'Switch the target chain' is essentially a tautology that restates the tool name 'switch-chain' without adding meaningful specificity. While it indicates a chain-switching action, it doesn't clarify what 'target chain' refers to, what system or context this switching affects, or how this differs from sibling tools like 'get-chain-id' or 'get-chains'.

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

Usage Guidelines1/5

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

The description provides absolutely no guidance on when to use this tool versus alternatives. There's no mention of prerequisites, appropriate contexts, or comparison to sibling tools like 'get-chain-id' (which retrieves current chain) or 'get-chains' (which might list available chains). The agent receives zero usage direction.

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/Xiawpohr/mcpilot'

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