MCP integration
Connect tools from an existing MCP service to DataAgent, then call them through TUI, HTTP, or the SDK. Connections belong in .mcp.yaml; you do not need to write a new Python tool or MCP service. The calculator below is already supplied by the repository. For a real service, obtain its launch command or remote endpoint from its provider.
Choose the connection location
| Location | Scope | Example registered name |
|---|---|---|
<home>/.mcp.yaml |
Tools shared in this Home | mcp__user__math__add |
.mcp.yaml at an enabled plugin root |
Tools enabled with that plugin | mcp__analytics__math__add, where analytics is the plugin ID |
Only these two sources are read. A .mcp.yaml next to a product YAML is not automatically loaded because of --config; disabled plugins do not contribute MCP connections. See Use plugins and the MCP configuration reference.
Connect the existing local stdio example
From the repository root, prepare Python and a separate Home. Copy the supplied service and connection configuration without implementing a server:
uv sync --python 3.12
export MCP_PYTHON="$(uv run --no-sync python -c 'import sys; print(sys.executable)')"
export DATAAGENT_HOME="$(mktemp -d)"
cp examples/mcp/.mcp.yaml examples/mcp/math_server.py "$DATAAGENT_HOME/"The connection file contains:
mcpServers:
math:
type: stdio
command: $env{MCP_PYTHON}
args:
- math_server.pycommand names the service program and args supplies separate arguments. The subprocess working directory is the directory containing .mcp.yaml, so it finds the neighboring math_server.py. For another local service, use its provider's launch command and arguments rather than placing a complete shell command in command. Use the service entry's env for additional subprocess environment values.
In an existing Home, merge the required math entry and retain other mcpServers. Check existing files before copying configuration or scripts.
Configure a model and start Server / TUI
MCP provides tools; model settings are separate. Save this minimal product configuration in the new Home:
cat > "$DATAAGENT_HOME/config.yaml" <<'YAML'
schema_version: 4
dataagent:
model: primary
models:
primary:
provider: openai
name: $env{LLM_MODEL}
base_url: $env{LLM_BASE_URL}
api_key: $env{LLM_API_KEY}
server:
host: 127.0.0.1
port: 8790
YAMLProvide LLM_MODEL, LLM_BASE_URL, and LLM_API_KEY in the repository-root .env; see first model configuration. Start from the same terminal so the process inherits DATAAGENT_HOME and MCP_PYTHON:
uv run --no-sync dataagent serve \
--config "$DATAAGENT_HOME/config.yaml" --env-file .envThe YAML server section selects the listener. If the port is occupied, change this configuration's server.port and use that port in the TUI URL. In another terminal, prepare the client dependencies and build with the TUI guide, then connect:
npm run start:tui -- --runtime-url http://127.0.0.1:8790When attaching to an existing Server, do not also pass --config or --env-file to TUI; the Server owns model and MCP loading. Ask:
Use mcp__user__math__add to add 12 and 30.Check the actual mcp__user__math__add call with a: 12 and b: 30, and verify the tool result is 42. A model answer of 42 alone does not prove an MCP invocation. Inspect the Server Home's trace files for call evidence.
Connect a remote MCP service
Put the full MCP endpoint supplied by the provider in Home or an enabled plugin's .mcp.yaml. For example, Streamable HTTP:
mcpServers:
analytics:
type: http
url: https://mcp.example.com/mcp
headers:
Authorization: Bearer $env{ANALYTICS_MCP_TOKEN}Choose type: http or type: sse as required by the service; their endpoints are not interchangeable. Replace the example URL and provide authentication variables in the selected environment file or process environment. Use the headers required by the provider, or omit headers when authentication is unnecessary. See mcp.full.yaml for all three transports.
$env{NAME} expands during loading; missing variables fail runtime preparation. Nonempty values in the launching process take precedence over the file selected by --env-file, which otherwise defaults to Home .env. A plugin-adjacent .env is not automatically loaded, and changing variables in another terminal does not update an existing process. See environment and paths.
Discovery, refresh, and invocation
Server discovers MCP tools before the conversation engine becomes ready. On failure, dataagent serve still returns HTTP 200 from /healthz with data.conversation.ready: false; /ready and conversation routes return 503. Correct the connection or configuration and restart Server.
| Change | How it takes effect |
|---|---|
| Local MCP connection map changes, such as added/removed services, endpoints, or resolved credentials | A ready Server attempts refresh when preparing the next turn and rediscovers tools when the effective map changes |
| Remote tool inventory changes without a local connection-map change | Restart Server to rediscover |
| A turn is already running | Retains its original graph and tools rather than changing them mid-run |
| Refresh fails | Rejects the triggering turn; correct the configuration and retry. The failed tool set is not published to running turns |
Model, Home, listener, or dataagent.entry changes |
Restart Server; these are outside MCP next-turn refresh |
Each tool call opens and closes its own MCP session; a stdio service starts for each invocation. Use files or external services for state that must persist. See extension lifecycle for fingerprints and caches.
Use MCP in the Python SDK
Discover tools explicitly and pass them to create_agent. The SDK guide creates runtime with prepare_runtime:
from dataagent import create_agent, load_mcp_tools
agent = create_agent(runtime, mcp_tools=await load_mcp_tools(runtime))Configured MCP connections without mcp_tools cause agent creation to report the missing tools. SDK callers own loading and updates; they do not automatically receive the Server's next-turn refresh behavior.
Distinguish NL2SQL's MCP database connection
Host .mcp.yaml adds service tools to the Agent. NL2SQL over MCP is a separate plugin database connection: configure plugins.config.nl2sql.database.engine: mcp and database.path; the plugin invokes its configured reader for queries and EXPLAIN.
The two configurations do not replace one another. Host authentication, discovery, hooks, and tool counts apply to host MCP tools. See the NL2SQL plugin for database endpoints, reader settings, and response structure.
Verify and diagnose
| Symptom | Check first |
|---|---|
| Missing environment variable before startup | Selected --env-file, nonempty process overrides, and MCP_PYTHON in the launching process environment |
/ready returns 503 |
MCP discovery failed or MCP discovery timed out in backend.log; check program paths, endpoints, authentication, and connectivity |
| Server ready but a tool is missing | Correct Home, enabled plugin, supported .mcp.yaml location, and registered name prefix; a compiled direct dataagent.entry does not automatically mount host MCP tools into the plugin graph |
| Newly published remote tool is absent | Restart to rediscover when the local connection map is unchanged |
| Tool returns an error | Inspect the actual tool result and logs, then follow the service provider's diagnostics |
Verify discovery, invocation, and cleanup of the supplied calculator without a real model:
uv run --no-sync pytest -q tests/test_mcp.py::test_documented_local_example_is_runnableThis test covers the local MCP path, not integration with a real remote service. See troubleshooting for other failures.