ClaudeCode.MCP (ClaudeCode v0.36.3)

View Source

Integration with the Model Context Protocol (MCP).

This module provides the MCP integration layer. Custom tools are defined with ClaudeCode.MCP.Server and passed via :mcp_servers.

Usage

Define tools with ClaudeCode.MCP.Server and pass them via :mcp_servers:

defmodule MyApp.Tools do
  use ClaudeCode.MCP.Server, name: "my-tools"

  tool :add do
    description "Add two numbers"

    field :x, :integer, required: true
    field :y, :integer, required: true
    def execute(%{x: x, y: y}), do: {:ok, "#{x + y}"}
  end
end

{:ok, result} = ClaudeCode.query("What is 5 + 3?",
  mcp_servers: %{"my-tools" => MyApp.Tools},
  allowed_tools: ["mcp__my-tools__add"]
)

See the Custom Tools guide for details.

Summary

Functions

Determines which backend handles the given MCP module.

Functions

backend_for(module)

@spec backend_for(module()) :: :sdk | {:subprocess, module()} | :unknown

Determines which backend handles the given MCP module.

Returns:

  • :sdk — in-process SDK server (handled via Router, no subprocess)
  • {:subprocess, backend_module} — subprocess server, with the backend that can expand it
  • :unknown — unrecognized module