MCP bridge

July 28, 2026 · View on GitHub

MongrelDB Viewer exposes its database tools to external model clients through:

  • an in-app loopback HTTP JSON-RPC server sharing the GUI connection,
  • a separate headless JSON-lines stdio process.

MCP bridge

Pick a transport

TransportDatabase stateBest for
In-app HTTPShares the current GUI Direct/Server connectionLocal clients while Viewer is open
StdioOpens its own Direct/Server connection from environmentIDE/terminal-managed child process

Stdio does not attach to the GUI process. A stdio Direct process cannot open a root already locked by GUI Direct mode.

In-app HTTP

  1. Connect a database.
  2. Open MCP.
  3. Choose a port, default 7337.
  4. Click Start MCP.
  5. Use the displayed http://127.0.0.1:<port>/mcp URL.
  6. Click Stop MCP when finished.

The UI always binds host 127.0.0.1. The backend can accept another host internally, but the public desktop form does not expose it. Use a port from 1 through 65,535.

Starting MCP again stops the prior listener before binding the new one. If the new bind fails, the prior listener is already stopped.

Routes

MethodPathPurpose
GET/Plain-text service hint
GET/healthJSON health check
POST/mcpJSON-RPC requests
GET/sseMinimal endpoint advertisement only

Health:

curl http://127.0.0.1:7337/health

Expected:

{"ok":true,"service":"mongreldb-viewer-mcp"}

Protocol methods

Viewer advertises MCP protocol version 2024-11-05 and implements:

MethodResult
initializeServer info, protocol version, tools capability, instructions
notifications/initializedAccepted
initializedAccepted alias
pingEmpty success object
tools/listComplete tool definitions
tools/callTool output
resources/listEmpty resources array
prompts/listEmpty prompts array

Unknown methods return JSON-RPC error -32601.

Initialize with curl

curl \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl","version":"1"}}}' \
  http://127.0.0.1:7337/mcp

List tools:

curl \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' \
  http://127.0.0.1:7337/mcp

Call list_tables:

curl \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"list_tables","arguments":{}}}' \
  http://127.0.0.1:7337/mcp

Tool calls return:

  • pretty JSON in content[0].text,
  • the native JSON value in structuredContent,
  • isError: true when the tool failed.

A tool failure is represented inside a successful JSON-RPC result so the model client can read it.

HTTP compatibility boundary

The HTTP implementation is a direct POST JSON-RPC endpoint. It does not implement streamable-HTTP session IDs or a full SSE event stream. /sse returns one endpoint event for probing.

Clients that accept a URL-based MCP JSON-RPC endpoint can use it. Clients that require a full session/stream transport may need stdio or a small compatible bridge.

Client configuration

Viewer displays a generic URL snippet:

{
  "mcpServers": {
    "mongreldb-viewer": {
      "url": "http://127.0.0.1:7337/mcp"
    }
  }
}

The exact settings file and transport key depend on the client. Use the endpoint shown in Viewer rather than assuming port 7337.

Stdio

Build or install the binary, then launch:

MONGRELDB_VIEWER_PATH=/absolute/path/to/root \
  /absolute/path/to/mongreldb-viewer --mcp-stdio

Server mode:

MONGRELDB_VIEWER_SERVER=http://127.0.0.1:8453 \
  /absolute/path/to/mongreldb-viewer --mcp-stdio

Optional Server auth variables:

MONGRELDB_VIEWER_TOKEN
MONGRELDB_VIEWER_USER
MONGRELDB_VIEWER_PASSWORD

If both Direct path and Server URL are set, Direct wins. Direct stdio has no environment-variable support for catalog credentials or encryption passphrases. Set MONGRELDB_VIEWER_USER and MONGRELDB_VIEWER_PASSWORD together for Server basic auth.

With neither variable, the process starts with no database. Schema, SQL, and search tools return no database is open.

Generic stdio client entry

{
  "mcpServers": {
    "mongreldb-viewer": {
      "command": "/absolute/path/to/mongreldb-viewer",
      "args": ["--mcp-stdio"],
      "env": {
        "MONGRELDB_VIEWER_PATH": "/absolute/path/to/root"
      }
    }
  }
}

For Server auth, inject secrets through the client's secret/environment facility. Do not commit tokens or passwords into a settings file.

Stdio framing

Viewer reads one JSON-RPC object per newline and writes one response object per newline. Blank lines are ignored. Parse failures return code -32700. Notifications whose method starts with notifications/ and whose ID is null produce no stdout response.

Connection lifecycle

In-app

  • Tools resolve the GUI's current connection at call time.
  • Reconnecting changes the database used by later calls.
  • Disconnect does not stop the HTTP listener.
  • While disconnected, database tools return no database is open.
  • Stop MCP separately from the MCP page.

Stdio

  • The child owns its connection until stdin closes or the process exits.
  • Direct owns its own exclusive lock.
  • Server mode is multi-client.
  • No GUI is created.

Tool reference

list_tables

Lists all tables with row counts, column/index counts, index-family flags, and embedding dimensions.

Input:

{}

Mode: read.

describe_table

Returns schema ID, row count, columns, flags, indexes, radar counts, and Direct-mode foreign keys.

Input:

{
  "table": "documents"
}

table is required.

Mode: read.

database_overview

Returns connection metadata, linked engine/query versions, all table summaries, and loaded embedding providers.

Input:

{}

Mode: read.

execute_sql

Runs arbitrary SQL.

Input:

{
  "sql": "SELECT id, status FROM documents LIMIT 25",
  "max_rows": 500
}
ArgumentRequiredDefaultBounds
sqlYesNon-empty string
max_rowsNo5001..10,000

Mode: read or write. There is no SQL allowlist.

Embeds query text locally and searches one table.

Input:

{
  "table": "documents",
  "embedding_column": "embedding",
  "query": "hybrid retrieval",
  "k": 5,
  "provider_id": "viewer-minilm",
  "exact_rerank": true,
  "min_score": 0.25,
  "projection": "id, body, status"
}
ArgumentRequiredDefaultNotes
tableYesOne table only
queryYesNatural-language text
embedding_columnNoembeddingMust have ANN
kNo5Backend clamps 1..1,000
provider_idNoRecorded sourceRequired for application-supplied vectors; must match their model
exact_rerankNotruePrefer ann_search_exact
min_scoreNoOffCosine floor where exact/native cosine score exists
projectionNoAutoSQL projection string

Direct prefers native retrieve_text; Server uses ANN SQL. Search reads source metadata but never changes it.

Mode: read.

install_dense_ann

Adds/rebuilds ANN and optionally backfills vectors. Direct only.

Minimal:

{
  "table": "documents",
  "source_text_column": "body"
}

Full example:

{
  "table": "documents",
  "embedding_column": "embedding",
  "dimension": 384,
  "source_text_column": "body",
  "provider_id": "viewer-minilm",
  "backfill_limit": 5000,
  "algorithm": "hnsw",
  "quantization": "product",
  "product_num_subvectors": 48,
  "product_bits": 8,
  "rebuild": true
}
ArgumentDefaultNotes
tableRequiredDirect table
embedding_columnembeddingAdded nullable when absent
dimension384Valid 1..4,096
source_text_columnNoneWhen set, backfill vectors
provider_idviewer-minilmMust be available
backfill_limitNoneOptional preflight ceiling; omit for all eligible rows
algorithmhnswhnsw, diskann, ivf
quantizationdensedense, binary_sign, product
product_num_subvectorsRequired for ProductMust divide dimension
product_bits8Only 8 supported
diskann_rEngine defaultDiskANN degree
diskann_lEngine defaultDiskANN build search list
diskann_beam_widthEngine defaultDiskANN query beam
ivf_nlistEngine defaultIVF lists
ivf_nprobeEngine defaultIVF probes
rebuildfalseDrop current ANN before create

Supported pairs:

hnsw × dense
hnsw × binary_sign
hnsw × product
diskann × dense
ivf × dense

Mode: schema and data write.

Backfill reads rows by stable internal RowId, embeds and validates all vectors before schema mutation, then writes every vector in one transaction. If an explicit backfill_limit is below the eligible row count, the call fails without partial work.

reindex

Runs analyze, compact, and garbage collection.

One table:

{
  "table": "documents"
}

Whole database:

{}

Direct calls the local engine. Server sends REINDEX SQL. Simple table names must contain only ASCII letters, digits, and underscore.

Mode: maintenance write.

constellation

Returns database/table/column/index graph nodes and edges.

Input:

{}

Mode: read.

list_embedding_providers

Returns process-loaded embedding providers. The local provider does not appear until load was attempted successfully or failed.

Input:

{}

Mode: read.

Security

The in-app HTTP server:

  • has no authentication,
  • has no tool-level authorization,
  • can execute mutating tools,
  • is intended for loopback only,
  • remains alive across database disconnect until explicitly stopped.

Any local process able to reach the port can call it. OS user separation, firewall policy, and local process trust are the security boundary.

For stdio, the parent client can invoke every tool and read every response. Environment secrets are visible to the child and may be visible to process inspection depending on OS policy.

Troubleshooting

  • Address already in use: choose another port.
  • No database is open: connect in the same GUI process, or set a stdio connection variable.
  • Direct action required: install_dense_ann cannot mutate a Server connection.
  • Client rejects HTTP transport: use stdio or a bridge supporting the client's required session transport.
  • Tool call isError: inspect structuredContent.error.
  • Stdio has no replies: send one complete JSON object followed by newline; do not use HTTP Content-Length framing.
  • Direct stdio lock error: disconnect GUI Direct first.

Related: Agent · ANN · Connections · Security