Back to Woods

MCP Servers

docs/MCP_SERVERS.md

1.2.010.6 KB
Original Source

MCP Servers

Woods ships two MCP (Model Context Protocol) servers that integrate with AI development tools like Claude Code, Cursor, and Windsurf.

Overview

Index ServerConsole Server
PurposeQuery pre-extracted codebase dataRun live queries against a Rails app
Requires Rails?No — reads JSON from diskYes — bridges to a Rails process
Tools2631
TransportStdio (default), HTTPStdio
Data sourcetmp/woods/ outputLive database + application state
SafetyRead-only (extraction output)Rolled-back transactions, SQL validation

Choosing the Right Tool

I want to...ToolServer
Look up a specific model or controllerlookupIndex
Search for code patternssearchIndex
Find what depends on a unitdependentsIndex
Find what a unit depends ondependenciesIndex
Trace an execution flowtrace_flowIndex
Count database recordsconsole_countConsole
Sample records for debuggingconsole_sampleConsole
Check database schemaconsole_schemaConsole
Diagnose a model's dataconsole_diagnose_modelConsole
Monitor job queuesconsole_job_queuesConsole
Find dead codegraph_analysisIndex
Check codebase healthpipeline_statusIndex

For detailed examples with parameters and expected output, see MCP Tool Cookbook.


Index Server

The Index Server reads pre-extracted data from disk and serves it via MCP. No Rails boot required — it works with the JSON output from rake woods:extract.

Setup

bash
# Start with stdio transport (default for MCP clients)
woods-mcp /path/to/rails-app/tmp/woods

# Or use the self-healing wrapper (installs deps, validates index)
woods-mcp-start /path/to/rails-app/tmp/woods

# HTTP transport (for shared/remote access)
woods-mcp-http /path/to/rails-app/tmp/woods

Claude Code Configuration

json
{
  "mcpServers": {
    "woods": {
      "command": "woods-mcp-start",
      "args": ["/path/to/rails-app/tmp/woods"]
    }
  }
}

Cursor / Windsurf Configuration

json
{
  "mcpServers": {
    "woods": {
      "command": "woods-mcp",
      "args": ["/path/to/rails-app/tmp/woods"]
    }
  }
}

Docker Note

The Index Server runs on the host, not inside Docker. It reads static JSON files and does not need Rails. Point it at the volume-mounted extraction output using the host-side path:

json
{
  "mcpServers": {
    "woods": {
      "command": "woods-mcp-start",
      "args": ["./tmp/woods"]
    }
  }
}

Do not use the container path (e.g., /app/tmp/woods) — the server cannot access it. The woods-mcp-start wrapper validates the directory and manifest.json before starting.

See DOCKER_SETUP.md for the full Docker guide including Console Server configuration.

Tools (26)

Core Query (6)

ToolDescription
lookupLook up a code unit by exact identifier. Options for including source and selecting metadata sections.
searchSearch units by regex pattern across identifiers, source code, or metadata fields.
dependenciesTraverse forward dependencies (what a unit depends on) with BFS depth control.
dependentsTraverse reverse dependencies (what depends on a unit) with BFS depth control.
structureGet codebase structure: manifest summary or full unit breakdown by type.
recent_changesList recently modified units sorted by git timestamp.

Graph Analysis (3)

ToolDescription
graph_analysisStructural analysis: orphans, dead ends, hubs, cycles, bridges.
pagerankPageRank importance scores — higher means more structurally central.
frameworkSearch Rails/gem framework source by concept keyword (e.g., "has_many", "before_action").

Flow & Session (2)

ToolDescription
trace_flowTrace execution flow from an entry point (e.g., UsersController#create) through the codebase.
session_traceAssemble context from browser session traces (requires session tracer middleware).

Semantic Search (1)

ToolDescription
codebase_retrieveNatural language query with semantic search, ranked by relevance within a token budget. Requires embedding provider configuration.

Pipeline Management (5)

ToolDescription
pipeline_extractTrigger extraction pipeline (full or incremental). Rate-limited to 5-minute cooldown.
pipeline_embedTrigger embedding generation for extracted units.
pipeline_statusCurrent pipeline state: last extraction time, unit counts, staleness indicators.
pipeline_diagnoseClassify a pipeline error and suggest remediation steps.
pipeline_repairClear stale locks or reset rate limit cooldowns.

Feedback (4)

ToolDescription
retrieval_rateRecord quality rating (1-5) for a retrieval result.
retrieval_report_gapReport a missing unit that should have appeared in results.
retrieval_explainGet feedback statistics: average scores, gap counts, trends.
retrieval_suggestAnalyze feedback to suggest retrieval improvements.

Temporal Snapshots (4)

ToolDescription
list_snapshotsList past extraction snapshots with timestamps and branch info.
snapshot_diffCompare two snapshots — added, modified, deleted units.
unit_historyTrack how a single unit changed across snapshots.
snapshot_detailFull metadata for a specific snapshot by git SHA.

Notion (1)

ToolDescription
notion_syncSync models and columns to a Notion database. Requires notion_api_token and notion_database_ids configuration.

Utility (1)

ToolDescription
reloadReload extraction data from disk without restarting the server.

Resources

URIDescription
codebase://manifestExtraction manifest with version info, unit counts, git metadata
codebase://graphFull dependency graph with nodes, edges, type index

Resource Templates

URI TemplateDescription
codebase://unit/{identifier}Look up a single unit by identifier
codebase://type/{type}List all units of a given type

Console Server

The Console Server connects to a live Rails application and provides database queries, model diagnostics, job monitoring, and guarded operations — all within rolled-back transactions.

Setup

bash
woods-console-mcp

The console server uses a bridge architecture to communicate with a Rails process. Configure the connection in console.yml:

yaml
# console.yml
connection:
  mode: direct           # direct, docker, or ssh
  # For docker mode:
  # mode: docker
  # service: web
  # compose_file: docker-compose.yml

Tools (31)

Tier 1: Read-Only (9 tools)

Safe, foundational queries against the live database.

ToolDescription
console_countCount records matching scope conditions
console_sampleRandom sample of records (max 25)
console_findFind a single record by primary key or unique column
console_pluckExtract column values with optional distinct (max 1000 rows)
console_aggregateRun sum/avg/min/max on a column
console_association_countCount associated records for a specific record
console_schemaDatabase schema for a model with optional index info
console_recentRecently created/updated records (max 50)
console_statusSystem health: available models and connection status

Tier 2: Domain-Aware (9 tools)

Higher-level operations: diagnostics, validation, settings, policies.

ToolDescription
console_diagnose_modelFull model diagnostic: counts, recent records, aggregates
console_data_snapshotRecord with associations for debugging (depth 1-3)
console_validate_recordRun validations on an existing record with optional changes
console_check_settingCheck a configuration setting value
console_update_settingUpdate a setting (requires confirmation)
console_check_policyCheck authorization policy for a record and user
console_validate_withValidate attributes against a model without persisting
console_check_eligibilityCheck feature eligibility for a record
console_decorateInvoke a decorator and return computed attributes

Tier 3: Analytics (10 tools)

Performance metrics, job monitoring, cache stats.

ToolDescription
console_slow_endpointsSlowest endpoints by response time
console_error_ratesError rates by controller or overall
console_throughputRequest throughput over time
console_job_queuesJob queue statistics
console_job_failuresRecent job failures
console_job_findFind a job by ID, optionally retry
console_job_scheduleScheduled/upcoming jobs
console_redis_infoRedis server information by section
console_cache_statsCache store statistics
console_channel_statusActionCable channel status

Tier 4: Guarded (3 tools)

Require explicit confirmation or have strict validation.

ToolDescription
console_evalExecute Ruby code (requires confirmation, 10s timeout)
console_sqlExecute read-only SQL (SELECT only, validated)
console_queryEnhanced query builder with joins and grouping

Safety Layers

The Console Server implements defense-in-depth:

  1. SafeContext — Every operation runs in a database transaction that is always rolled back. Writes are silently discarded.
  2. SqlValidator — Rejects DML (INSERT/UPDATE/DELETE) and DDL (CREATE/ALTER/DROP) at the string level before any database interaction.
  3. Confirmation — Tier 4 operations and settings updates require explicit human approval.
  4. AuditLogger — All operations are logged to a JSONL file for review.
  5. ModelValidator — Validates model names against ActiveRecord::Base.descendants to prevent arbitrary class instantiation.

Job Backend Adapters

The console server auto-detects your job backend:

BackendAdapterSupported Operations
SidekiqSidekiqAdapterQueue stats, failures, find, retry, schedule
Solid QueueSolidQueueAdapterQueue stats, failures, find, retry, schedule
GoodJobGoodJobAdapterQueue stats, failures, find, retry, schedule