fleet-memory/hindsight-api/tests
DK09876 fedfb494ee
feat: add TenantExtension auth to MCP endpoint (#286)
* feat: add TenantExtension auth to MCP endpoint

Replace static MCP_AUTH_TOKEN check with TenantExtension authentication,
making MCP use the same auth path as REST API.

- MCPMiddleware now calls tenant_extension.authenticate()
- Sets _current_schema from TenantContext for multi-tenant isolation
- Returns 401 on AuthenticationError (same as REST API)
- DefaultTenantExtension: no auth (local dev)
- ApiKeyTenantExtension: validates against env var
- CloudTenantExtension: HMAC + DB lookup (production)

Adds tests for middleware auth rejection, acceptance, and schema routing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Address PR review: backwards compatibility for MCP auth

- Keep MCP_AUTH_TOKEN env var for legacy MCP servers
- Add authenticate_mcp() method to TenantExtension base class
  - Default implementation calls authenticate()
  - Extensions can override to opt-out of MCP auth
- Add mcp_auth_disabled config option to ApiKeyTenantExtension
  - Set HINDSIGHT_API_TENANT_MCP_AUTH_DISABLED=true to skip MCP auth
- Remove CloudTenantExtension from public docstring
- Add tests for legacy auth token and mcp_auth_disabled flag
- Update MCP docs with new auth configuration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add search_docs MCP tool for documentation search

Implements a new MCP tool that searches Hindsight documentation using
Vectorize RAG pipelines. The tool supports:
- Searching core (OSS) docs, cloud docs, or both
- Configurable number of results (1-10)
- Returns ranked results with URLs, similarity scores, and text snippets

New environment variables:
- HINDSIGHT_API_VECTORIZE_ORG_ID
- HINDSIGHT_API_VECTORIZE_API_TOKEN
- HINDSIGHT_API_VECTORIZE_CORE_PIPELINE_ID
- HINDSIGHT_API_VECTORIZE_CLOUD_PIPELINE_ID
- HINDSIGHT_API_VECTORIZE_API_BASE_URL

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add documentation for search_docs MCP tool

- Add Vectorize environment variables to configuration.md
- Add search_docs tool to MCP server available tools
- Add reflect tool documentation (was missing)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add tests for search_docs MCP tool

Tests cover:
- DocsSource enum values and parsing
- _clean_text HTML stripping helper
- _search_vectorize_pipeline with mocked httpx
- Tool registration and function execution
- Source filtering (core/cloud/all)
- Result sorting by similarity
- Error handling for pipeline failures
- HTML cleaning in results
- Invalid source defaulting to 'all'

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Move search_docs to hindsight-cloud, add MCPExtension pattern

- Add MCPExtension base class for registering additional MCP tools
- Load MCPExtension in create_mcp_server when configured
- Remove search_docs tool (moved to hindsight-cloud CloudMCPExtension)
- Remove Vectorize config from hindsight-core
- Add tests for MCPExtension pattern
- Update docs to remove search_docs references

The MCPExtension pattern allows cloud (or any extension package) to
register additional MCP tools via:
  HINDSIGHT_API_MCP_EXTENSION=package.module:ExtensionClass

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Address PR review feedback

- Remove CloudTenantExtension mention from MCPMiddleware docstring
- Fix docs: clarify that ApiKeyTenantExtension must be explicitly enabled
- Revert changes to versioned docs (0.3 and 0.4) - synced automatically on release

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Format mcp.py line length

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-06 12:28:05 -07:00
..
fixtures rename to hindsight (#2) 2025-11-25 19:28:26 +01:00
__init__.py rename to hindsight (#2) 2025-11-25 19:28:26 +01:00
conftest.py fix: improve claude code and codex for /reflect (#285) 2026-02-04 13:34:45 +01:00
test_admin_backup_restore.py feat: run db migrations offline (optionally) (#114) 2026-01-07 15:49:51 +01:00
test_agents_api.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_batch_chunking.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_causal_relations.py fix: duplicated causal relationships and token optimization (#126) 2026-01-08 14:43:48 +01:00
test_causal_relationships.py fix: duplicated causal relationships and token optimization (#126) 2026-01-08 14:43:48 +01:00
test_chunking.py improve retain performances, caching and tests 2025-12-08 18:21:56 +01:00
test_combined_scoring.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_config_validation.py fix: hindsight-embed profiles are not loaded correctly (#316) 2026-02-06 17:13:54 +01:00
test_consolidation.py fix: deadlock in worker polling (#250) 2026-01-30 11:09:29 +01:00
test_custom_embedding_dimension.py fix: improve mental model consolidation (#197) 2026-01-26 09:54:25 +01:00
test_document_tracking.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_extensions.py fix: improve mental model consolidation (#197) 2026-01-26 09:54:25 +01:00
test_fact_extraction_analysis.py chore: remove dead code (#245) 2026-01-30 09:16:32 +01:00
test_fact_extraction_output_ratio.py fix: misc perf improvements (#133) 2026-01-08 22:49:04 +01:00
test_fact_extraction_quality.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_fact_ordering.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_http_api_integration.py fix: retain async with timestamp might fails (#253) 2026-01-30 14:54:32 +01:00
test_link_expansion_retrieval.py fix: misc fixes for observations and mental models (#209) 2026-01-27 15:37:57 +01:00
test_link_utils.py prepare for release 2025-12-03 11:52:25 +01:00
test_llm_provider.py fix(ci): resolve flaky test failures in api tests (#311) 2026-02-06 13:56:59 +01:00
test_llm_token_metrics.py feat: support for codex and claude-code as llm (#276) 2026-02-02 12:54:44 +01:00
test_llm_tools.py chore: internal renames (#204) 2026-01-27 09:53:28 +01:00
test_load_large_batch.py feat: new 'worker' service (#176) 2026-01-20 10:17:56 +01:00
test_main_module.py fix: improve mental model consolidation (#197) 2026-01-26 09:54:25 +01:00
test_mcp_extension.py feat: add TenantExtension auth to MCP endpoint (#286) 2026-02-06 12:28:05 -07:00
test_mcp_local.py feat(mcp): add timestamp to retain (#190) 2026-01-23 16:00:43 +01:00
test_mcp_routing.py feat: add TenantExtension auth to MCP endpoint (#286) 2026-02-06 12:28:05 -07:00
test_mcp_tools.py feat(mcp): add timestamp to retain (#190) 2026-01-23 16:00:43 +01:00
test_mental_model_hooks.py Add extension hooks for mental model operations (#260) 2026-01-31 09:30:53 -05:00
test_mental_models.py fix: hindsight-embed profiles are not loaded correctly (#316) 2026-02-06 17:13:54 +01:00
test_metrics.py chore: remove dead code (#245) 2026-01-30 09:16:32 +01:00
test_mpfp_retrieval.py fix: improve mpfp retrieval (#146) 2026-01-12 18:58:05 +01:00
test_multilingual.py chore: remove dead code (#245) 2026-01-30 09:16:32 +01:00
test_observations.py chore: remove dead code (#245) 2026-01-30 09:16:32 +01:00
test_per_operation_llm_config.py feat: add more config options for llm retries (#234) 2026-01-29 17:50:43 +01:00
test_provider_default_models.py feat: support for codex and claude-code as llm (#276) 2026-02-02 12:54:44 +01:00
test_query_analyzer.py fix: ci and ui build (#9) 2025-12-03 15:47:53 +01:00
test_reflect_agent.py fix: graph endpoint not showing links for observations (#214) 2026-01-28 14:51:25 +01:00
test_reflections.py feat: improve mental models ux on control plane (#297) 2026-02-04 15:49:03 +01:00
test_retain.py feat: ai sdk integration (#299) 2026-02-04 20:25:59 +01:00
test_schema_isolation.py fix: improve mental model consolidation (#197) 2026-01-26 09:54:25 +01:00
test_search_trace.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_server_module.py fix: improve mental model consolidation (#197) 2026-01-26 09:54:25 +01:00
test_sql_schema_safety.py chore: internal renames (#204) 2026-01-27 09:53:28 +01:00
test_tags_visibility.py chore: cleanup benchmarks runner with old flags (#212) 2026-01-28 13:22:48 +01:00
test_tei_cross_encoder.py fix: add defensive error handling to PyTorch device detection (#221) 2026-01-28 18:14:54 +01:00
test_temporal_ranges.py feat(mcp): add timestamp to retain (#190) 2026-01-23 16:00:43 +01:00
test_think.py chore: remove dead code (#245) 2026-01-30 09:16:32 +01:00
test_vertexai_provider.py Switch Vertex AI provider to native genai SDK (#242) 2026-01-30 08:35:59 +01:00
test_worker.py fix: worker doesn't pick up correct default schema (#259) 2026-01-31 09:15:59 +01:00