Skip to main content
Glama

switch-chain

Switch blockchain networks in MetaMask by specifying chain ID or adding new chains with required parameters for Ethereum wallet operations.

Instructions

Switch the target chain.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainIdYesID of chain to switch to.
addEthereumChainParameterNoAdd not configured chains to Ethereum wallets.

Implementation Reference

  • The execute handler that switches to the specified chainId using wagmi's switchChain function. Optionally adds chain configuration if provided. Updates the internal chains state and returns the result as a JSON string.
    execute: async (args) => {
      const chainId = args.chainId as typeof wagmiConfig["chains"][number]["id"];
      const addEthereumChainParameter = args.addEthereumChainParameter;
    
      const result = await switchChain(wagmiConfig, {
        chainId,
        addEthereumChainParameter,
      });
    
      wagmiConfig._internal.chains.setState(x => [...x, result]);
    
      return {
        content: [
          {
            type: "text",
            text: JSONStringify(result),
          },
        ],
      };
    },
  • Zod input schema defining required chainId and optional addEthereumChainParameter for configuring new chains.
    parameters: z.object({
      chainId: z.coerce.number().describe("ID of chain to switch to."),
      addEthereumChainParameter: z.object({
        chainName: z.string(),
        nativeCurrency: z.object({
          name: z.string(),
          symbol: z.string(),
          decimals: z.coerce.number(),
        }),
        rpcUrls: z.string().array().min(1),
        blockExplorerUrls: z.string().array().optional(),
        iconUrls: z.string().array().optional(),
      }).optional().describe("Add not configured chains to Ethereum wallets."),
    }),
  • The registration function that adds the "switch-chain" tool to the FastMCP server, including schema and handler.
    export function registerSwitchChainTools(server: FastMCP, wagmiConfig: Config): void {
      server.addTool({
        name: "switch-chain",
        description: "Switch the target chain.",
        parameters: z.object({
          chainId: z.coerce.number().describe("ID of chain to switch to."),
          addEthereumChainParameter: z.object({
            chainName: z.string(),
            nativeCurrency: z.object({
              name: z.string(),
              symbol: z.string(),
              decimals: z.coerce.number(),
            }),
            rpcUrls: z.string().array().min(1),
            blockExplorerUrls: z.string().array().optional(),
            iconUrls: z.string().array().optional(),
          }).optional().describe("Add not configured chains to Ethereum wallets."),
        }),
        execute: async (args) => {
          const chainId = args.chainId as typeof wagmiConfig["chains"][number]["id"];
          const addEthereumChainParameter = args.addEthereumChainParameter;
    
          const result = await switchChain(wagmiConfig, {
            chainId,
            addEthereumChainParameter,
          });
    
          wagmiConfig._internal.chains.setState(x => [...x, result]);
    
          return {
            content: [
              {
                type: "text",
                text: JSONStringify(result),
              },
            ],
          };
        },
      });
    };
  • Invocation of the switch-chain registration as part of the overall tools registration.
    registerSwitchChainTools(server, wagmiConfig);
  • src/index.ts:15-15 (registration)
    Top-level call to register all MCP tools, which includes switch-chain.
    registerTools(server, wagmiConfig);
Behavior2/5

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

No annotations are provided, so the description carries full burden. 'Switch' implies a mutation/write operation, but the description doesn't disclose behavioral traits like whether this requires user confirmation in a wallet, what happens on failure (e.g., chain not supported), or if it changes global state. It lacks context on permissions, side effects, or error conditions.

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 a single, efficient sentence with no wasted words. It's front-loaded with the core action. However, it could be more informative by specifying context (e.g., 'Switch the active blockchain network in a connected wallet'), but as-is, it's appropriately concise.

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 (mutation tool with nested parameters, no annotations, no output schema), the description is inadequate. It doesn't explain what 'target chain' means, the expected behavior (e.g., prompts user, updates wallet), return values, or error handling. For a tool that likely interacts with a wallet or blockchain provider, more context is needed for safe and correct 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%, with clear descriptions for both parameters: 'chainId' as 'ID of chain to switch to' and 'addEthereumChainParameter' as 'Add not configured chains to Ethereum wallets.' The description adds no additional meaning beyond the schema, but the schema provides adequate documentation, meeting the baseline score of 3 for high coverage.

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

Purpose3/5

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

The description 'Switch the target chain' clearly states the verb ('switch') and resource ('target chain'), making the basic purpose understandable. However, it doesn't specify what 'target chain' refers to (e.g., blockchain network in a wallet context) or differentiate from siblings like 'get-chain-id' or 'get-chains' that retrieve chain information rather than switch to one.

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 doesn't mention prerequisites (e.g., needing a connected wallet), exclusions, or compare to siblings like 'get-chain-list' for listing available chains. The agent must infer usage from the name and schema alone.

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/metamask-mcp'

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