Skip to content

fix: pass --index flag through to MCP server#344

Open
fourcolors wants to merge 3 commits intotobi:mainfrom
fourcolors:fix/mcp-index-flag
Open

fix: pass --index flag through to MCP server#344
fourcolors wants to merge 3 commits intotobi:mainfrom
fourcolors:fix/mcp-index-flag

Conversation

@fourcolors
Copy link

Summary

  • startMcpServer() and startMcpHttpServer() now accept an optional dbPath parameter instead of always calling createStore() with no arguments
  • The CLI passes the resolved storeDbPathOverride (set by --index) when dispatching to MCP stdio and HTTP transports
  • Daemon mode (--daemon) forwards --index to the spawned child process args

Problem

qmd --index myproject mcp silently ignores the --index flag. The MCP server always opens ~/.cache/qmd/index.sqlite instead of ~/.cache/qmd/myproject.sqlite.

Root cause: src/mcp.ts imports createStore directly from store.ts and calls it with no arguments, bypassing the storeDbPathOverride that setIndexName() sets in qmd.ts.

Changes

File Change
src/mcp.ts Add optional dbPath param to startMcpServer() and startMcpHttpServer()
src/qmd.ts Pass storeDbPathOverride to both MCP entry points; forward --index in daemon spawn args
test/mcp.test.ts New test: starts HTTP server with explicit dbPath (no INDEX_PATH env), verifies search works
CHANGELOG.md Entry under [Unreleased]

Test plan

  • New test "server uses dbPath instead of default index.sqlite" — starts HTTP MCP server with dbPath, clears INDEX_PATH env, searches seeded data
  • All existing MCP tests pass (41 passed, 16 skipped LLM-dependent)
  • Manual: qmd --index foo mcp opens foo.sqlite via stdio
  • Manual: qmd --index foo mcp --http opens foo.sqlite via HTTP
  • Manual: qmd --index foo mcp --http --daemon spawns child with --index foo

Fixes #343

Copilot AI review requested due to automatic review settings March 9, 2026 20:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug (#343) where the --index CLI flag was silently ignored by the MCP server. Previously, both startMcpServer() and startMcpHttpServer() always called createStore() with no arguments, bypassing the storeDbPathOverride set when --index is parsed in qmd.ts.

Changes:

  • startMcpServer() and startMcpHttpServer() in src/mcp.ts now accept an optional dbPath parameter passed through to createStore()
  • src/qmd.ts passes the resolved storeDbPathOverride to both MCP entry points; daemon mode forwards --index in spawned child process args
  • A new integration test in test/mcp.test.ts verifies the HTTP server uses an explicit dbPath (with INDEX_PATH unset)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/mcp.ts Added optional dbPath parameter to both exported MCP server start functions
src/qmd.ts Passes storeDbPathOverride to MCP functions; adds --index forwarding in daemon spawn args
test/mcp.test.ts New describe block tests that startMcpHttpServer uses the provided dbPath instead of defaulting to INDEX_PATH
CHANGELOG.md [Unreleased] entry documenting the fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danil09234
Copy link

Hey! I was excited to try this fix since I'm hitting the same issue (#343). Cloned the branch and ran npm install && npm run build but got a TypeScript error:

src/qmd.ts(2948,29): error TS2552: Cannot find name 'indexName'. Did you mean 'setIndexName'?
src/qmd.ts(2948,53): error TS2552: Cannot find name 'indexName'. Did you mean 'setIndexName'?

Haven't dug super deep into it though, so I might be missing something! Just wanted to flag it in case it helps.

@fourcolors
Copy link
Author

@danil09234 ah shoot Ill fix this up one moment. Thanks for the feedback!

startMcpServer() and startMcpHttpServer() called createStore() with no
arguments, ignoring the --index flag set via setIndexName() in the CLI.
Both functions now accept an optional dbPath parameter, and the CLI
passes the resolved path when dispatching to MCP. Daemon mode also
forwards --index to the spawned child process.

Fixes tobi#343
- Use consistent options bag for both startMcpServer() and
  startMcpHttpServer() instead of mixing positional and bag styles
- Use getDbPath() instead of raw storeDbPathOverride for robustness
- Move env snapshot into beforeAll to avoid stale module-load captures
- Add local mcpReq helper instead of duplicating fetch boilerplate
indexName was a local variable inside parseCLI() but was referenced
in the main CLI block. Use cli.values.index instead, which is the
parsed value already available in scope. Fixes TS2552 build error.
@fourcolors
Copy link
Author

@danil09234 can you try again, this should be working now

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.

MCP server ignores --index flag (always uses default index.sqlite)

3 participants