Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions examples/mcp-query/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
_recipe: Optional[Recipe] = None
_config_path: str = "./ov.conf"
_data_path: str = "./data"
_api_key: str = ""
_default_uri: str = ""


def _get_recipe() -> Recipe:
Expand Down Expand Up @@ -137,14 +139,15 @@ async def search(
score_threshold: Minimum relevance score (0.0-1.0, default: 0.2).
target_uri: Optional URI to scope the search to a specific resource.
"""
effective_uri = target_uri or _default_uri

def _search_sync():
recipe = _get_recipe()
return recipe.search(
query=query,
top_k=top_k,
score_threshold=score_threshold,
target_uri=target_uri or None,
target_uri=effective_uri or None,
)

results = await asyncio.to_thread(_search_sync)
Expand Down Expand Up @@ -239,14 +242,19 @@ def parse_args():
# Use stdio transport (for Claude Desktop integration)
uv run server.py --transport stdio

# Connect from Claude CLI
claude mcp add --transport http openviking http://localhost:2033/mcp
# Connect from Claude CLI (use 127.0.0.1 instead of localhost for Windows compatibility)
claude mcp add --transport http openviking http://127.0.0.1:2033/mcp

# With API key and default search scope
uv run server.py --api-key sk-xxx --default-uri viking://user/memories

Environment variables:
OV_CONFIG Path to config file (default: ./ov.conf)
OV_DATA Path to data directory (default: ./data)
OV_PORT Server port (default: 2033)
OV_DEBUG Enable debug logging (set to 1)
OV_CONFIG Path to config file (default: ./ov.conf)
OV_DATA Path to data directory (default: ./data)
OV_PORT Server port (default: 2033)
OV_API_KEY API key for OpenViking server authentication
OV_DEFAULT_URI Default target URI for search scoping
OV_DEBUG Enable debug logging (set to 1)
""",
)
parser.add_argument(
Expand Down Expand Up @@ -280,15 +288,29 @@ def parse_args():
default="streamable-http",
help="Transport type (default: streamable-http)",
)
parser.add_argument(
"--api-key",
type=str,
default=os.getenv("OV_API_KEY", ""),
help="API key for OpenViking server authentication (default: $OV_API_KEY)",
)
parser.add_argument(
"--default-uri",
type=str,
default=os.getenv("OV_DEFAULT_URI", ""),
help="Default target URI for search scoping (default: search all)",
)
return parser.parse_args()


def main():
args = parse_args()

global _config_path, _data_path
global _config_path, _data_path, _api_key, _default_uri
_config_path = args.config
_data_path = args.data
_api_key = args.api_key
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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.

_default_uri = args.default_uri

if os.getenv("OV_DEBUG") == "1":
logging.getLogger().setLevel(logging.DEBUG)
Expand Down
Loading