Skip to content

Conversation

@RobbieMcKinstry
Copy link
Contributor

FEATURE: Add MCP server with JSON-RPC 2.0 protocol over stdio

This implements the full MCP server infrastructure for tern:

Phase 1 - Foundation:

  • Create src/mcp/ module structure with error types and protocol handling
  • Implement JSON-RPC 2.0 message parsing and routing
  • Implement stdio transport layer for newline-delimited JSON
  • Add 'tern mcp' CLI subcommand
  • Implement MCP initialize, ping, and capability negotiation

Phase 2 - Resources:

  • Implement tern://schema resource for current schema introspection
  • Implement tern://migrations resource for listing migrations
  • Implement tern://migration/{id} resource for migration details

Phase 3 - PGLite Integration:

  • Implement lazy database initialization for sessions
  • Use SchemaExporter to set up base state in session databases
  • Enable namespace extraction via PostgresCatalog

Phase 4 - Session Management:

  • Implement Session and SessionManager types
  • Add start_session, cancel_session, list_sessions tools

Phase 5 - Session Operations:

  • Implement execute_sql tool with full PGLite integration
  • Implement get_session_schema tool for schema introspection
  • Implement get_session_diff tool for comparing against base state
  • Add apply_operation tool stub for structured operations
  • Add generate_migration tool stub for migration generation

The MCP server enables AI assistants to:

  • Read current schema and migration history
  • Start isolated migration authoring sessions
  • Execute SQL against in-memory PostgreSQL (PGLite)
  • Compare schema changes and generate migrations

FEATURE: Add MCP server with JSON-RPC 2.0 protocol over stdio

This implements the full MCP server infrastructure for tern:

Phase 1 - Foundation:
- Create src/mcp/ module structure with error types and protocol handling
- Implement JSON-RPC 2.0 message parsing and routing
- Implement stdio transport layer for newline-delimited JSON
- Add 'tern mcp' CLI subcommand
- Implement MCP initialize, ping, and capability negotiation

Phase 2 - Resources:
- Implement tern://schema resource for current schema introspection
- Implement tern://migrations resource for listing migrations
- Implement tern://migration/{id} resource for migration details

Phase 3 - PGLite Integration:
- Implement lazy database initialization for sessions
- Use SchemaExporter to set up base state in session databases
- Enable namespace extraction via PostgresCatalog

Phase 4 - Session Management:
- Implement Session and SessionManager types
- Add start_session, cancel_session, list_sessions tools

Phase 5 - Session Operations:
- Implement execute_sql tool with full PGLite integration
- Implement get_session_schema tool for schema introspection
- Implement get_session_diff tool for comparing against base state
- Add apply_operation tool stub for structured operations
- Add generate_migration tool stub for migration generation

The MCP server enables AI assistants to:
- Read current schema and migration history
- Start isolated migration authoring sessions
- Execute SQL against in-memory PostgreSQL (PGLite)
- Compare schema changes and generate migrations
CHORE: Workaround for pglite_oxide creating files in cwd instead of OS tempdir
FEATURE: Add complete implementations for schema mutation and migration generation

- Implement apply_operation with operation parsing, SQL rendering via
  PostgresRenderer, execution against PGLite session database, and
  operation history tracking
- Implement generate_migration with full diff-to-migration pipeline:
  loads current schema from session's PGLite, diffs against base state,
  detects breaking changes, creates Migration object, saves via backend
- Both tools require pglite feature; non-pglite versions return appropriate
  error messages
@RobbieMcKinstry RobbieMcKinstry merged commit 3253e82 into trunk Jan 26, 2026
6 checks passed
@RobbieMcKinstry RobbieMcKinstry deleted the claude/implement-mcp-server-bjsGu branch January 26, 2026 15:35
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.

2 participants