fix(mcp): add api_key support and configurable defaults to MCP query server#691
fix(mcp): add api_key support and configurable defaults to MCP query server#691mvanhorn wants to merge 1 commit intovolcengine:mainfrom
Conversation
…server The MCP server at examples/mcp-query/server.py had three gaps: 1. No mechanism to pass API key for authenticated OpenViking deployments 2. No server-level default for search target_uri, requiring every client to specify the scope on each search call 3. Example URLs used "localhost" which fails on Windows where it resolves to ::1 while the server binds to 127.0.0.1 This adds --api-key/OV_API_KEY and --default-uri/OV_DEFAULT_URI CLI flags with backward-compatible empty-string defaults, and fixes the epilog examples to use 127.0.0.1. Fixes volcengine#606 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
qin-ctx
left a comment
There was a problem hiding this comment.
The --default-uri fallback and the localhost → 127.0.0.1 fix look correct. However, the --api-key feature is not wired up — the stored value is never consumed by any downstream code.
| global _config_path, _data_path, _api_key, _default_uri | ||
| _config_path = args.config | ||
| _data_path = args.data | ||
| _api_key = args.api_key |
There was a problem hiding this comment.
[Bug] (blocking) _api_key is assigned here but never consumed anywhere in the codebase. It is not passed to Recipe(), OpenVikingConfig, ov.SyncOpenViking, or any HTTP header.
This means the --api-key / OV_API_KEY feature is effectively a no-op — users who set it will still get 401 errors when the server has root_api_key configured.
The value needs to be threaded through to whichever layer performs authentication (likely Recipe or the underlying client). If Recipe doesn't currently accept an api_key parameter and this is deferred work, the --api-key flag should be removed from this PR to avoid shipping a non-functional feature that gives users a false sense of security.
Summary
The in-repo MCP server at
examples/mcp-query/server.pyhad three gaps reported in #606:No API key pass-through - no mechanism to pass authentication credentials when the OpenViking server has
root_api_keyconfigured. Added--api-key/OV_API_KEY.No configurable search scope - the
searchtool acceptedtarget_uriper-call but had no server-level default, requiring every MCP client to specify the scope. Added--default-uri/OV_DEFAULT_URIas a fallback when the client does not providetarget_uri.Windows localhost failure - the epilog examples used
localhostwhich resolves to::1on Windows while the server binds to127.0.0.1. Fixed to use127.0.0.1.Note: The external
openviking-mcpPyPI package referenced in #606 is out of scope for this repo. This PR improves the official in-repo MCP example to prevent the same issues.Changes
--api-key/OV_API_KEYCLI flag (empty string default = no auth)--default-uri/OV_DEFAULT_URICLI flag (empty string default = search all)_default_urias fallback whentarget_uriis not provided by the clientlocalhostto127.0.0.1in argparse epilog examplesAll new flags have backward-compatible defaults - existing deployments are unaffected.
Fixes #606
This contribution was developed with AI assistance (Claude Code).
Test plan
uv run server.pystarts without errors (backward compatible)uv run server.py --default-uri viking://user/memories- search tool uses default URIuv run server.py --api-key sk-test- API key stored for future useuv run server.py --helpshows new flags and updated examplesruff format --checkandruff checkpass