MCP Tools (Model Context Protocol)

Use MCP servers as a tool source: discover tool schemas via tools/list, inject them into LLM calls, and keep execution host-owned.

Design principle

MCP is treated as a tool protocol, not an LLM provider. AbstractCore providers generate text/tool calls; your host/runtime decides what to execute and where.

Discover tool specs from an MCP server

AbstractCore converts MCP tool schemas into AbstractCore-compatible tool specs that you can pass to tools=[...].

from abstractcore import create_llm
from abstractcore.mcp import McpClient, McpToolSource

llm = create_llm("openai", model="gpt-5-mini")

# MCP Streamable HTTP transport (JSON-RPC over HTTP POST)
client = McpClient(url="http://localhost:3000/mcp")
tool_specs = McpToolSource(server_id="local", client=client).list_tool_specs()

response = llm.generate("Call an MCP tool if needed.", tools=tool_specs)
print(response.tool_calls)

Tools are namespaced to avoid collisions: mcp::<server_id>::<tool_name>

Execute MCP tool calls (host/runtime)

By default, AbstractCore returns tool calls; it does not execute them. To execute MCP tool calls, parse the namespaced name and route to the correct server.

from abstractcore.mcp import McpClient, parse_namespaced_tool_name

client = McpClient(url="http://localhost:3000/mcp")

for call in response.tool_calls or []:
    parsed = parse_namespaced_tool_name(call.get("name", ""))
    if not parsed:
        continue

    server_id, tool_name = parsed.server_id, parsed.tool_name
    args = call.get("arguments") or {}

    # In a real host/runtime: look up server_id → client/connection
    result = client.call_tool(name=tool_name, arguments=args)
    print(server_id, tool_name, result)

Security & operational guidance

  • Whitelist tool servers: only connect to trusted MCP endpoints.
  • Keep execution explicit: treat tool calls like untrusted user input; validate args and apply allowlists.
  • Separate privileges: run high-privilege tools on hardened hosts/containers; consider separate tool workers.
  • Auditability: log tool calls + results at the host boundary.

Related Documentation

Tool Calling System

How tool calls are surfaced and executed

HTTP Server Guide

OpenAI-compatible API (tool_calls + agent_format)

Tool Syntax Rewriting

tool_call_tags vs agent_format