Access tools from MCP servers as LLM tools
Install this plugin in the same environment as LLM.
llm install llm-mcp-clientThis plugin registers a toolbox called MCP which connects to an MCP server, discovers the tools it exposes and makes them available as LLM tools.
Pass the URL of an MCP server to the toolbox:
llm -T 'MCP("https://example.com/mcp")' 'Ask something that needs a tool' --tdThe --td option shows details of the tool calls as they execute.
It works in llm chat too:
llm chat -T 'MCP("https://example.com/mcp")'You can save an MCP to a named LLM template like this:
llm -T 'MCP("https://datasette.simonwillison.net/-/mcp")' --save blogNow you can query it without specifying the full tool definition like this:
llm -t blog 'count entries and notes'By default the client negotiates the protocol automatically. You can force a specific mode with the mode= argument:
# Force modern stateless MCP:
llm -T 'MCP("https://example.com/mcp", mode="stateless")' '...'
# Force the legacy initialize handshake:
llm -T 'MCP("https://example.com/mcp", mode="legacy")' '...'If you are using tools from more than one server and their names might clash, give each server a prefix:
llm -T 'MCP("https://one.example.com/mcp", prefix="one_")' \
-T 'MCP("https://two.example.com/mcp", prefix="two_")' '...'import llm
from llm_mcp_client import MCP
model = llm.get_model("gpt-4.1-mini")
result = model.chain(
"Ask something that needs a tool",
tools=[MCP("https://example.com/mcp")],
).text()Tool results containing MCP image or audio content are returned to the model as LLM attachments. An MCP error result raises llm_mcp_client.MCPToolError, which LLM passes back to the model as an error message.
To set up this plugin locally, first checkout the code. Then run the tests with uv:
cd llm-mcp-client
uv run pytestTo run LLM with your in-development plugin:
uv run llm --help