Skip to content

feat: built-in MCP server for AI tool integration#825

Merged
datlechin merged 22 commits intomainfrom
feat/mcp-server
Apr 21, 2026
Merged

feat: built-in MCP server for AI tool integration#825
datlechin merged 22 commits intomainfrom
feat/mcp-server

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

  • Built-in MCP (Model Context Protocol) server lets AI tools (Claude Desktop, Claude Code, Cursor, Windsurf) query databases through TablePro's existing connections
  • 13 tools: list_connections, connect, disconnect, execute_query, list_tables, describe_table, list_databases, list_schemas, get_table_ddl, export_data, get_connection_status, switch_database, switch_schema
  • 3 resources: connections list, schema cache, query history
  • SSE transport on localhost:23508 via Network.framework (NWListener)
  • Full security: respects per-connection AIConnectionPolicy and SafeModeLevel
  • Settings tab with enable toggle, port config, row limits, and copy-to-clipboard config snippet
  • Query classification extracted to reusable QueryClassifier utility

Architecture

  • MCPServer (actor): NWListener lifecycle, session management, SSE
  • MCPRouter: HTTP/1.1 parsing, JSON-RPC 2.0 dispatch
  • MCPConnectionBridge (actor): MainActor hop to DatabaseManager, driver dispatch
  • MCPAuthGuard (actor): AIConnectionPolicy + SafeModeLevel enforcement
  • MCPToolHandler / MCPResourceHandler: 13 tool + 3 resource implementations
  • MCPServerManager (@mainactor): bridges AppDelegate/Settings to server actor

New files (11)

  • Core/MCP/MCPServer.swift, MCPRouter.swift, MCPHTTPParser.swift, MCPSession.swift, MCPMessageTypes.swift
  • Core/MCP/MCPConnectionBridge.swift, MCPAuthGuard.swift, MCPToolHandler.swift, MCPResourceHandler.swift, MCPServerManager.swift
  • Core/Utilities/SQL/QueryClassifier.swift
  • Models/Settings/MCPSettings.swift
  • Views/Settings/MCPSettingsView.swift

Modified files (5)

  • AppSettingsStorage.swift + AppSettingsManager.swift (MCP settings)
  • AppDelegate.swift (server lifecycle)
  • SettingsView.swift (MCP tab)
  • MainContentCoordinator+QueryAnalysis.swift (delegate to QueryClassifier)

Test plan

  • Build succeeds (xcodebuild -scheme TablePro build -skipPackagePluginValidation)
  • Enable MCP in Settings, status shows "Running"
  • Copy config snippet to Claude Desktop, verify connection
  • list_connections returns saved connections without passwords
  • connectlist_tablesdescribe_tableexecute_query flow works
  • Read-only connection blocks write queries via MCP
  • aiPolicy == .never connection returns FORBIDDEN
  • Disable MCP in Settings, server stops
  • SwiftLint passes

@datlechin datlechin merged commit d8d1a88 into main Apr 21, 2026
2 checks passed
@datlechin datlechin deleted the feat/mcp-server branch April 21, 2026 17:06
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