KTXDocs
Guides

Serving Agents

Expose your context to Claude Code, Cursor, Codex, and other coding agents.

Once you've built and refined your context, the final step is exposing it to coding agents. KTX provides two channels: an MCP server for persistent integration with tools like Claude Code and Cursor, and CLI commands for direct terminal access.

MCP Server

The MCP (Model Context Protocol) server gives agents structured access to your entire context layer — semantic sources, knowledge pages, scans, and ingestion — through a standard tool-calling interface.

Starting the server

ktx serve --mcp stdio

This starts an MCP server on stdio, which is how Claude Code, Cursor, and other MCP-compatible tools communicate with KTX. You typically don't run this manually — your agent's configuration handles it.

Configuration options

FlagDescriptionDefault
--mcp <mode>MCP transport mode (currently stdio)Required
--user-id <id>User identifier for knowledge scopinglocal
--semantic-computeEnable semantic layer planning and query executionfalse
--semantic-compute-url <url>URL for the semantic compute daemon
--database-introspection-url <url>Daemon URL for live database access
--execute-queriesAllow agents to execute SQL queriesfalse
--memory-captureEnable memory capture from conversationsfalse
--memory-model <model>LLM model for memory capture

Available tools

When an agent connects via MCP, it can call these tools:

Connections

ToolDescription
connection_listList configured data connections
connection_testTest a connection through the scan connector

Semantic Layer

ToolDescription
sl_list_sourcesList sources, optionally filtered by connection or search query
sl_read_sourceRead a source YAML by connection and name
sl_write_sourceCreate, replace, or delete a source
sl_validateValidate sources against the database schema
sl_queryExecute a semantic query — returns rows, SQL, and query plan

Knowledge

ToolDescription
knowledge_searchSearch knowledge pages by query, returns ranked summaries
knowledge_readRead a knowledge page by key
knowledge_writeCreate or replace a knowledge page

Scanning

ToolDescription
scan_triggerRun a structural, enriched, or relationship scan
scan_statusCheck the status of a running scan
scan_reportRead a completed scan report
scan_list_artifactsList files produced by a scan run
scan_read_artifactRead a scan artifact by path

Ingestion

ToolDescription
ingest_triggerTrigger an ingest run for an adapter and connection
ingest_statusCheck ingest progress, including diff and work-unit summaries
ingest_reportRead a stored ingest report
ingest_replayRead the memory-flow replay for a past ingest

Memory

ToolDescription
memory_captureCapture knowledge and semantic updates from a conversation
memory_capture_statusCheck the status of a memory capture run

How agents use these tools

A typical agent interaction flows like this:

  1. Agent calls connection_list to see available databases
  2. Agent calls sl_list_sources to discover what semantic sources exist
  3. Agent calls knowledge_search to find business context relevant to the user's question
  4. Agent calls sl_query with measures, dimensions, and filters to get data
  5. Agent presents results with the business context it found

Agents should use the semantic layer for analytics questions because it enforces correct joins, grain-aware aggregation, and consistent metric definitions. If SQL execution is enabled, KTX only allows read-only SQL with row limits.

CLI Commands

For agents that work through the terminal rather than MCP, KTX provides a set of machine-readable commands under ktx agent. These return JSON output designed for programmatic consumption.

Available commands

# List available tools and their descriptions
ktx agent tools --json

# Get project context for planning
ktx agent context --json

Semantic layer:

# List sources
ktx agent sl list --json
ktx agent sl list --json --connection-id my-postgres

# Read a source
ktx agent sl read orders --json --connection-id my-postgres

# Run a query from a JSON file
ktx agent sl query --json \
  --connection-id my-postgres \
  --query-file query.json \
  --execute \
  --max-rows 100

Knowledge:

# Search knowledge pages
ktx agent wiki search "revenue recognition" --json --limit 10

# Read a specific page
ktx agent wiki read order-status-definitions --json

SQL execution:

# Execute read-only SQL with a row limit
ktx agent sql execute --json \
  --connection-id my-postgres \
  --sql-file query.sql \
  --max-rows 500

When to use CLI vs MCP

MCPCLI
Best forPersistent agent integrationsTerminal-based workflows, scripting
ProtocolStructured tool calls over stdioShell commands with JSON output
Used byClaude Code, Cursor, CodexShell scripts, custom agents, debugging
StateServer runs continuouslyStateless per invocation

Most users should set up MCP — it gives agents richer context and a more natural interaction model. The CLI commands are useful for scripting, debugging, and agents that operate through terminal tools.

Setting Up Your Agent

The fastest way to connect an agent is through the setup wizard:

ktx setup

The agents step auto-detects installed tools and generates the right configuration. For manual setup or per-tool details, see the Agent Clients integration page.

Quick manual setup

Claude Code — add to .claude/settings.json:

{
  "mcpServers": {
    "ktx": {
      "command": "ktx",
      "args": ["serve", "--mcp", "stdio", "--semantic-compute", "--execute-queries"],
      "env": {
        "KTX_PROJECT_DIR": "/path/to/your/ktx/project"
      }
    }
  }
}

Cursor — add to .cursor/mcp.json:

{
  "mcpServers": {
    "ktx": {
      "command": "ktx",
      "args": ["serve", "--mcp", "stdio", "--semantic-compute", "--execute-queries"],
      "env": {
        "KTX_PROJECT_DIR": "/path/to/your/ktx/project"
      }
    }
  }
}

After configuration, the agent can immediately start calling KTX tools — listing sources, searching knowledge, and querying your semantic layer.