Skip to content

feat(chatd): add chat-level MCP server support - #23020

Closed
kylecarbs wants to merge 1 commit into
mainfrom
kylecarbs/agents-mcp-servers
Closed

kylecarbs wants to merge 1 commit into
mainfrom
kylecarbs/agents-mcp-servers

Conversation

@kylecarbs

@kylecarbs kylecarbs commented Mar 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the ability for admins to attach MCP (Model Context Protocol) servers to individual chats. MCP servers provide additional tools to the chat agent, enabling integration with external services like Linear, GitHub, Sentry, etc.

API

POST /api/experimental/chats

{
  "content": [{"type": "text", "text": "What are my open issues?"}],
  "mcp_servers": [  // optional, admin-only
    {
      "slug": "linear",
      "url": "https://mcp.linear.app/sse",
      "display_name": "Linear",
      "auth_headers": {"Authorization": "Bearer lin_api_..."},
      "tool_allow_regex": "",
      "tool_deny_regex": "delete_.*"
    }
  ]
}

POST /api/experimental/chats/{id}/messages

Same mcp_servers field to update the config on subsequent messages.

Response

Chat objects include mcp_servers in responses (auth headers are always stripped).

Design decisions

  • Chat-level config, not a global registry. Each chat is self-contained with its MCP configuration. No shared table, no admin UI, no CRUD API. A global registry can be layered on later.
  • Admin-only. The mcp_servers field requires ActionUpdate on ResourceDeploymentConfig. Non-admins who omit it get a normal chat.
  • Parallel discovery with hard failure. MCP servers are connected in parallel (30s timeout). If any server fails, the chat errors — because the admin configured it and expects it to work.
  • JSONB column on chats table. Single nullable column, read once per chat turn, never queried on. Minimal schema impact.

Implementation

  • chattool.MCPServer() — Connects to a remote MCP server via Streamable HTTP, initializes the protocol, discovers tools, filters by allow/deny regex, and returns fantasy.AgentTool instances named mcp__{slug}__{tool_name}.
  • chatd.runChat() — Parses chat.MCPServers JSONB, connects to all servers in parallel, registers tools before the chat loop starts.
  • Auth headers are passed to MCP servers but never returned in API responses.

Tests

  • chattool/mcpserver_test.go (8 subtests) — Tool discovery, tool execution, error handling, allow/deny regex filtering, empty servers, invalid input.
  • chatd_test.go (2 integration tests):
    • TestChatMCPServerConnectionFailure — Dead URL → chat errors with MCP message.
    • TestChatMCPServerToolsDiscovered — Real MCP server → tools registered, chat completes.

@kylecarbs
kylecarbs force-pushed the kylecarbs/agents-mcp-servers branch 5 times, most recently from 055959c to f395164 Compare March 16, 2026 16:57
Adds the ability for admins to attach MCP (Model Context Protocol)
servers to individual chats. MCP servers provide additional tools
to the chat agent, enabling integration with external services.

API changes:
- POST /chats accepts optional mcp_servers field (admin-only)
- POST /chats/{id}/messages accepts mcp_servers to update config
- Chat responses include mcp_servers (auth headers stripped)

Implementation:
- New JSONB column on chats table stores per-chat MCP config
- chatd reads mcp_servers from chat row, discovers tools via
  Streamable HTTP transport, filters by allow/deny regex, and
  registers them as fantasy.AgentTool with mcp__{slug}__{name}
- MCP server failures are logged but never block the chat
- Auth headers are passed to MCP servers but never returned in API

No global MCP server registry, no admin UI, no separate table.
Each chat is self-contained with its MCP configuration.
@kylecarbs
kylecarbs force-pushed the kylecarbs/agents-mcp-servers branch from f395164 to 4a140e7 Compare March 16, 2026 17:01
@kylecarbs kylecarbs changed the title feat(agents): add MCP server configuration to agents page feat(chatd): add chat-level MCP server support Mar 16, 2026
@kylecarbs kylecarbs closed this Mar 18, 2026
@github-actions
github-actions Bot deleted the kylecarbs/agents-mcp-servers branch September 17, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant