@facthouse/mcp 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +611 -0
- package/dist/cli/index.d.ts +30 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +785 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init-backfill.d.ts +26 -0
- package/dist/cli/init-backfill.d.ts.map +1 -0
- package/dist/cli/init-backfill.js +56 -0
- package/dist/cli/init-backfill.js.map +1 -0
- package/dist/cli/init-knobs.d.ts +137 -0
- package/dist/cli/init-knobs.d.ts.map +1 -0
- package/dist/cli/init-knobs.js +400 -0
- package/dist/cli/init-knobs.js.map +1 -0
- package/dist/cli/init-wizard.d.ts +67 -0
- package/dist/cli/init-wizard.d.ts.map +1 -0
- package/dist/cli/init-wizard.js +319 -0
- package/dist/cli/init-wizard.js.map +1 -0
- package/dist/cli/init.d.ts +124 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +286 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/inspect-html.d.ts +15 -0
- package/dist/cli/inspect-html.d.ts.map +1 -0
- package/dist/cli/inspect-html.js +491 -0
- package/dist/cli/inspect-html.js.map +1 -0
- package/dist/cli/inspect-intelligence.d.ts +8 -0
- package/dist/cli/inspect-intelligence.d.ts.map +1 -0
- package/dist/cli/inspect-intelligence.js +103 -0
- package/dist/cli/inspect-intelligence.js.map +1 -0
- package/dist/cli/inspect-model.d.ts +42 -0
- package/dist/cli/inspect-model.d.ts.map +1 -0
- package/dist/cli/inspect-model.js +108 -0
- package/dist/cli/inspect-model.js.map +1 -0
- package/dist/cli/inspect-payload.d.ts +122 -0
- package/dist/cli/inspect-payload.d.ts.map +1 -0
- package/dist/cli/inspect-payload.js +338 -0
- package/dist/cli/inspect-payload.js.map +1 -0
- package/dist/cli/inspect-theme.d.ts +44 -0
- package/dist/cli/inspect-theme.d.ts.map +1 -0
- package/dist/cli/inspect-theme.js +118 -0
- package/dist/cli/inspect-theme.js.map +1 -0
- package/dist/cli/inspect.d.ts +24 -0
- package/dist/cli/inspect.d.ts.map +1 -0
- package/dist/cli/inspect.js +172 -0
- package/dist/cli/inspect.js.map +1 -0
- package/dist/cli/log-event.d.ts +55 -0
- package/dist/cli/log-event.d.ts.map +1 -0
- package/dist/cli/log-event.js +149 -0
- package/dist/cli/log-event.js.map +1 -0
- package/dist/cli/package-version.d.ts +2 -0
- package/dist/cli/package-version.d.ts.map +1 -0
- package/dist/cli/package-version.js +15 -0
- package/dist/cli/package-version.js.map +1 -0
- package/dist/cli/query.d.ts +53 -0
- package/dist/cli/query.d.ts.map +1 -0
- package/dist/cli/query.js +325 -0
- package/dist/cli/query.js.map +1 -0
- package/dist/cli/record.d.ts +55 -0
- package/dist/cli/record.d.ts.map +1 -0
- package/dist/cli/record.js +149 -0
- package/dist/cli/record.js.map +1 -0
- package/dist/cli/settings.d.ts +26 -0
- package/dist/cli/settings.d.ts.map +1 -0
- package/dist/cli/settings.js +161 -0
- package/dist/cli/settings.js.map +1 -0
- package/dist/cli/spend-dashboard.d.ts +53 -0
- package/dist/cli/spend-dashboard.d.ts.map +1 -0
- package/dist/cli/spend-dashboard.js +297 -0
- package/dist/cli/spend-dashboard.js.map +1 -0
- package/dist/cli/stats-html.d.ts +20 -0
- package/dist/cli/stats-html.d.ts.map +1 -0
- package/dist/cli/stats-html.js +879 -0
- package/dist/cli/stats-html.js.map +1 -0
- package/dist/cli/web.d.ts +60 -0
- package/dist/cli/web.d.ts.map +1 -0
- package/dist/cli/web.js +416 -0
- package/dist/cli/web.js.map +1 -0
- package/dist/config.d.ts +102 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +302 -0
- package/dist/config.js.map +1 -0
- package/dist/db/connection.d.ts +96 -0
- package/dist/db/connection.d.ts.map +1 -0
- package/dist/db/connection.js +200 -0
- package/dist/db/connection.js.map +1 -0
- package/dist/db/consolidation-lock.d.ts +16 -0
- package/dist/db/consolidation-lock.d.ts.map +1 -0
- package/dist/db/consolidation-lock.js +67 -0
- package/dist/db/consolidation-lock.js.map +1 -0
- package/dist/db/consolidations.d.ts +41 -0
- package/dist/db/consolidations.d.ts.map +1 -0
- package/dist/db/consolidations.js +165 -0
- package/dist/db/consolidations.js.map +1 -0
- package/dist/db/disk-budget.d.ts +44 -0
- package/dist/db/disk-budget.d.ts.map +1 -0
- package/dist/db/disk-budget.js +177 -0
- package/dist/db/disk-budget.js.map +1 -0
- package/dist/db/domains.d.ts +14 -0
- package/dist/db/domains.d.ts.map +1 -0
- package/dist/db/domains.js +37 -0
- package/dist/db/domains.js.map +1 -0
- package/dist/db/embeddings-hnsw.d.ts +30 -0
- package/dist/db/embeddings-hnsw.d.ts.map +1 -0
- package/dist/db/embeddings-hnsw.js +129 -0
- package/dist/db/embeddings-hnsw.js.map +1 -0
- package/dist/db/embeddings.d.ts +68 -0
- package/dist/db/embeddings.d.ts.map +1 -0
- package/dist/db/embeddings.js +139 -0
- package/dist/db/embeddings.js.map +1 -0
- package/dist/db/entities.d.ts +157 -0
- package/dist/db/entities.d.ts.map +1 -0
- package/dist/db/entities.js +489 -0
- package/dist/db/entities.js.map +1 -0
- package/dist/db/extract-watermarks.d.ts +55 -0
- package/dist/db/extract-watermarks.d.ts.map +1 -0
- package/dist/db/extract-watermarks.js +171 -0
- package/dist/db/extract-watermarks.js.map +1 -0
- package/dist/db/facts.d.ts +117 -0
- package/dist/db/facts.d.ts.map +1 -0
- package/dist/db/facts.js +326 -0
- package/dist/db/facts.js.map +1 -0
- package/dist/db/index.d.ts +26 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +23 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/inferences.d.ts +36 -0
- package/dist/db/inferences.d.ts.map +1 -0
- package/dist/db/inferences.js +212 -0
- package/dist/db/inferences.js.map +1 -0
- package/dist/db/intelligence-runs.d.ts +20 -0
- package/dist/db/intelligence-runs.d.ts.map +1 -0
- package/dist/db/intelligence-runs.js +60 -0
- package/dist/db/intelligence-runs.js.map +1 -0
- package/dist/db/pg-backend.d.ts +14 -0
- package/dist/db/pg-backend.d.ts.map +1 -0
- package/dist/db/pg-backend.js +53 -0
- package/dist/db/pg-backend.js.map +1 -0
- package/dist/db/postgres-schema.d.ts +13 -0
- package/dist/db/postgres-schema.d.ts.map +1 -0
- package/dist/db/postgres-schema.js +392 -0
- package/dist/db/postgres-schema.js.map +1 -0
- package/dist/db/postgres.d.ts +30 -0
- package/dist/db/postgres.d.ts.map +1 -0
- package/dist/db/postgres.js +154 -0
- package/dist/db/postgres.js.map +1 -0
- package/dist/db/prune.d.ts +67 -0
- package/dist/db/prune.d.ts.map +1 -0
- package/dist/db/prune.js +113 -0
- package/dist/db/prune.js.map +1 -0
- package/dist/db/scheduler-signal.d.ts +20 -0
- package/dist/db/scheduler-signal.d.ts.map +1 -0
- package/dist/db/scheduler-signal.js +32 -0
- package/dist/db/scheduler-signal.js.map +1 -0
- package/dist/db/schema-version.d.ts +7 -0
- package/dist/db/schema-version.d.ts.map +1 -0
- package/dist/db/schema-version.js +7 -0
- package/dist/db/schema-version.js.map +1 -0
- package/dist/db/schema.d.ts +12 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +983 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/session-facts.d.ts +108 -0
- package/dist/db/session-facts.d.ts.map +1 -0
- package/dist/db/session-facts.js +244 -0
- package/dist/db/session-facts.js.map +1 -0
- package/dist/db/sessions.d.ts +85 -0
- package/dist/db/sessions.d.ts.map +1 -0
- package/dist/db/sessions.js +169 -0
- package/dist/db/sessions.js.map +1 -0
- package/dist/db/sources.d.ts +22 -0
- package/dist/db/sources.d.ts.map +1 -0
- package/dist/db/sources.js +43 -0
- package/dist/db/sources.js.map +1 -0
- package/dist/db/stats.d.ts +94 -0
- package/dist/db/stats.d.ts.map +1 -0
- package/dist/db/stats.js +79 -0
- package/dist/db/stats.js.map +1 -0
- package/dist/db/store.d.ts +19 -0
- package/dist/db/store.d.ts.map +1 -0
- package/dist/db/store.js +58 -0
- package/dist/db/store.js.map +1 -0
- package/dist/db/watermarks.d.ts +20 -0
- package/dist/db/watermarks.d.ts.map +1 -0
- package/dist/db/watermarks.js +30 -0
- package/dist/db/watermarks.js.map +1 -0
- package/dist/embedding/ollama.d.ts +31 -0
- package/dist/embedding/ollama.d.ts.map +1 -0
- package/dist/embedding/ollama.js +148 -0
- package/dist/embedding/ollama.js.map +1 -0
- package/dist/embedding/provider.d.ts +37 -0
- package/dist/embedding/provider.d.ts.map +1 -0
- package/dist/embedding/provider.js +71 -0
- package/dist/embedding/provider.js.map +1 -0
- package/dist/embedding/types.d.ts +61 -0
- package/dist/embedding/types.d.ts.map +1 -0
- package/dist/embedding/types.js +13 -0
- package/dist/embedding/types.js.map +1 -0
- package/dist/embedding/voyage.d.ts +31 -0
- package/dist/embedding/voyage.d.ts.map +1 -0
- package/dist/embedding/voyage.js +105 -0
- package/dist/embedding/voyage.js.map +1 -0
- package/dist/identity.d.ts +32 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +53 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +275 -0
- package/dist/index.js.map +1 -0
- package/dist/intelligence/backing.d.ts +19 -0
- package/dist/intelligence/backing.d.ts.map +1 -0
- package/dist/intelligence/backing.js +88 -0
- package/dist/intelligence/backing.js.map +1 -0
- package/dist/intelligence/cli.d.ts +90 -0
- package/dist/intelligence/cli.d.ts.map +1 -0
- package/dist/intelligence/cli.js +823 -0
- package/dist/intelligence/cli.js.map +1 -0
- package/dist/intelligence/consolidate.d.ts +84 -0
- package/dist/intelligence/consolidate.d.ts.map +1 -0
- package/dist/intelligence/consolidate.js +1234 -0
- package/dist/intelligence/consolidate.js.map +1 -0
- package/dist/intelligence/extract-prompt.d.ts +78 -0
- package/dist/intelligence/extract-prompt.d.ts.map +1 -0
- package/dist/intelligence/extract-prompt.js +146 -0
- package/dist/intelligence/extract-prompt.js.map +1 -0
- package/dist/intelligence/heuristic.d.ts +15 -0
- package/dist/intelligence/heuristic.d.ts.map +1 -0
- package/dist/intelligence/heuristic.js +224 -0
- package/dist/intelligence/heuristic.js.map +1 -0
- package/dist/intelligence/http.d.ts +77 -0
- package/dist/intelligence/http.d.ts.map +1 -0
- package/dist/intelligence/http.js +496 -0
- package/dist/intelligence/http.js.map +1 -0
- package/dist/intelligence/provider-type.d.ts +6 -0
- package/dist/intelligence/provider-type.d.ts.map +1 -0
- package/dist/intelligence/provider-type.js +18 -0
- package/dist/intelligence/provider-type.js.map +1 -0
- package/dist/intelligence/provider.d.ts +49 -0
- package/dist/intelligence/provider.d.ts.map +1 -0
- package/dist/intelligence/provider.js +52 -0
- package/dist/intelligence/provider.js.map +1 -0
- package/dist/intelligence/related-k.d.ts +15 -0
- package/dist/intelligence/related-k.d.ts.map +1 -0
- package/dist/intelligence/related-k.js +57 -0
- package/dist/intelligence/related-k.js.map +1 -0
- package/dist/intelligence/routing-view.d.ts +33 -0
- package/dist/intelligence/routing-view.d.ts.map +1 -0
- package/dist/intelligence/routing-view.js +54 -0
- package/dist/intelligence/routing-view.js.map +1 -0
- package/dist/intelligence/sampling.d.ts +20 -0
- package/dist/intelligence/sampling.d.ts.map +1 -0
- package/dist/intelligence/sampling.js +324 -0
- package/dist/intelligence/sampling.js.map +1 -0
- package/dist/intelligence/stage-router.d.ts +32 -0
- package/dist/intelligence/stage-router.d.ts.map +1 -0
- package/dist/intelligence/stage-router.js +251 -0
- package/dist/intelligence/stage-router.js.map +1 -0
- package/dist/intelligence/steps.d.ts +65 -0
- package/dist/intelligence/steps.d.ts.map +1 -0
- package/dist/intelligence/steps.js +86 -0
- package/dist/intelligence/steps.js.map +1 -0
- package/dist/intelligence/subject.d.ts +42 -0
- package/dist/intelligence/subject.d.ts.map +1 -0
- package/dist/intelligence/subject.js +44 -0
- package/dist/intelligence/subject.js.map +1 -0
- package/dist/intelligence/token-budget.d.ts +86 -0
- package/dist/intelligence/token-budget.d.ts.map +1 -0
- package/dist/intelligence/token-budget.js +312 -0
- package/dist/intelligence/token-budget.js.map +1 -0
- package/dist/intelligence/types.d.ts +179 -0
- package/dist/intelligence/types.d.ts.map +1 -0
- package/dist/intelligence/types.js +7 -0
- package/dist/intelligence/types.js.map +1 -0
- package/dist/intelligence/usage.d.ts +104 -0
- package/dist/intelligence/usage.d.ts.map +1 -0
- package/dist/intelligence/usage.js +233 -0
- package/dist/intelligence/usage.js.map +1 -0
- package/dist/ipc/scheduler-ipc.d.ts +52 -0
- package/dist/ipc/scheduler-ipc.d.ts.map +1 -0
- package/dist/ipc/scheduler-ipc.js +214 -0
- package/dist/ipc/scheduler-ipc.js.map +1 -0
- package/dist/paths.d.ts +29 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +47 -0
- package/dist/paths.js.map +1 -0
- package/dist/scheduler.d.ts +39 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +93 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/schemas/domains.d.ts +89 -0
- package/dist/schemas/domains.d.ts.map +1 -0
- package/dist/schemas/domains.js +160 -0
- package/dist/schemas/domains.js.map +1 -0
- package/dist/schemas/starter-vocabulary.d.ts +34 -0
- package/dist/schemas/starter-vocabulary.d.ts.map +1 -0
- package/dist/schemas/starter-vocabulary.js +91 -0
- package/dist/schemas/starter-vocabulary.js.map +1 -0
- package/dist/search/ann.d.ts +36 -0
- package/dist/search/ann.d.ts.map +1 -0
- package/dist/search/ann.js +59 -0
- package/dist/search/ann.js.map +1 -0
- package/dist/search/entity.d.ts +43 -0
- package/dist/search/entity.d.ts.map +1 -0
- package/dist/search/entity.js +147 -0
- package/dist/search/entity.js.map +1 -0
- package/dist/search/episodes.d.ts +28 -0
- package/dist/search/episodes.d.ts.map +1 -0
- package/dist/search/episodes.js +102 -0
- package/dist/search/episodes.js.map +1 -0
- package/dist/search/hnsw-graph.d.ts +35 -0
- package/dist/search/hnsw-graph.d.ts.map +1 -0
- package/dist/search/hnsw-graph.js +177 -0
- package/dist/search/hnsw-graph.js.map +1 -0
- package/dist/search/hnsw-ram.d.ts +29 -0
- package/dist/search/hnsw-ram.d.ts.map +1 -0
- package/dist/search/hnsw-ram.js +95 -0
- package/dist/search/hnsw-ram.js.map +1 -0
- package/dist/search/index.d.ts +119 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +420 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/interlocutor-rank.d.ts +10 -0
- package/dist/search/interlocutor-rank.d.ts.map +1 -0
- package/dist/search/interlocutor-rank.js +21 -0
- package/dist/search/interlocutor-rank.js.map +1 -0
- package/dist/search/key-facts.d.ts +34 -0
- package/dist/search/key-facts.d.ts.map +1 -0
- package/dist/search/key-facts.js +43 -0
- package/dist/search/key-facts.js.map +1 -0
- package/dist/search/profile.d.ts +31 -0
- package/dist/search/profile.d.ts.map +1 -0
- package/dist/search/profile.js +43 -0
- package/dist/search/profile.js.map +1 -0
- package/dist/search/vector.d.ts +90 -0
- package/dist/search/vector.d.ts.map +1 -0
- package/dist/search/vector.js +187 -0
- package/dist/search/vector.js.map +1 -0
- package/dist/sources/claude-code.d.ts +35 -0
- package/dist/sources/claude-code.d.ts.map +1 -0
- package/dist/sources/claude-code.js +401 -0
- package/dist/sources/claude-code.js.map +1 -0
- package/dist/sources/copy.d.ts +58 -0
- package/dist/sources/copy.d.ts.map +1 -0
- package/dist/sources/copy.js +104 -0
- package/dist/sources/copy.js.map +1 -0
- package/dist/sources/cursor.d.ts +44 -0
- package/dist/sources/cursor.d.ts.map +1 -0
- package/dist/sources/cursor.js +99 -0
- package/dist/sources/cursor.js.map +1 -0
- package/dist/sources/jsonl-copy.d.ts +58 -0
- package/dist/sources/jsonl-copy.d.ts.map +1 -0
- package/dist/sources/jsonl-copy.js +195 -0
- package/dist/sources/jsonl-copy.js.map +1 -0
- package/dist/sources/jsonl-ingest.d.ts +58 -0
- package/dist/sources/jsonl-ingest.d.ts.map +1 -0
- package/dist/sources/jsonl-ingest.js +195 -0
- package/dist/sources/jsonl-ingest.js.map +1 -0
- package/dist/sources/pull.d.ts +85 -0
- package/dist/sources/pull.d.ts.map +1 -0
- package/dist/sources/pull.js +145 -0
- package/dist/sources/pull.js.map +1 -0
- package/dist/sources/resolve.d.ts +38 -0
- package/dist/sources/resolve.d.ts.map +1 -0
- package/dist/sources/resolve.js +91 -0
- package/dist/sources/resolve.js.map +1 -0
- package/dist/tools/capture-fact-description.d.ts +18 -0
- package/dist/tools/capture-fact-description.d.ts.map +1 -0
- package/dist/tools/capture-fact-description.js +41 -0
- package/dist/tools/capture-fact-description.js.map +1 -0
- package/dist/tools/fact-manager.d.ts +69 -0
- package/dist/tools/fact-manager.d.ts.map +1 -0
- package/dist/tools/fact-manager.js +332 -0
- package/dist/tools/fact-manager.js.map +1 -0
- package/dist/tools/inference-descriptions.d.ts +8 -0
- package/dist/tools/inference-descriptions.d.ts.map +1 -0
- package/dist/tools/inference-descriptions.js +16 -0
- package/dist/tools/inference-descriptions.js.map +1 -0
- package/dist/tools/inferences.d.ts +11 -0
- package/dist/tools/inferences.d.ts.map +1 -0
- package/dist/tools/inferences.js +98 -0
- package/dist/tools/inferences.js.map +1 -0
- package/dist/tools/read-tools.d.ts +21 -0
- package/dist/tools/read-tools.d.ts.map +1 -0
- package/dist/tools/read-tools.js +276 -0
- package/dist/tools/read-tools.js.map +1 -0
- package/dist/tools/resources.d.ts +62 -0
- package/dist/tools/resources.d.ts.map +1 -0
- package/dist/tools/resources.js +199 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/session-manager.d.ts +44 -0
- package/dist/tools/session-manager.d.ts.map +1 -0
- package/dist/tools/session-manager.js +227 -0
- package/dist/tools/session-manager.js.map +1 -0
- package/dist/types/config.d.ts +400 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +105 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/data.d.ts +357 -0
- package/dist/types/data.d.ts.map +1 -0
- package/dist/types/data.js +36 -0
- package/dist/types/data.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types.d.ts +115 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/warnings.d.ts.map +1 -0
- package/dist/warnings.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read tools — search and retrieve integrated knowledge.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { searchWithProvider } from "../search/index.js";
|
|
6
|
+
import { parseSystemTime } from "../db/facts.js";
|
|
7
|
+
import { getTopicContext, lookupNamedSubject } from "../search/entity.js";
|
|
8
|
+
import { getDomains } from "../db/domains.js";
|
|
9
|
+
import { getStats } from "../db/stats.js";
|
|
10
|
+
import { systemTimeWarning } from "../config.js";
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Registration
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
export function registerReadTools(server, db,
|
|
15
|
+
/** Null when semantic search is off, which is the shipped default. */
|
|
16
|
+
embedding = null,
|
|
17
|
+
/** How much of the semantic ranking survives. Store-configured. */
|
|
18
|
+
tuning,
|
|
19
|
+
/**
|
|
20
|
+
* Temporal mode. Bi-temporal exposes `as_of_system_time` on search;
|
|
21
|
+
* simple (the default) omits it so the tool description costs no extra tokens.
|
|
22
|
+
*/
|
|
23
|
+
temporal, interlocutor,
|
|
24
|
+
/** Copy new lines on a copy store. Must not throw. */
|
|
25
|
+
beforeRead) {
|
|
26
|
+
const bitemporal = temporal?.mode === "bitemporal";
|
|
27
|
+
// -----------------------------------------------------------------
|
|
28
|
+
// search_knowledge
|
|
29
|
+
// -----------------------------------------------------------------
|
|
30
|
+
const searchDescription = `Search the knowledge base. Call this BEFORE answering ` +
|
|
31
|
+
`questions that might benefit from what this store knows. If you have not ` +
|
|
32
|
+
`called get_session_context (or loaded memory://briefing) this conversation, ` +
|
|
33
|
+
`do that first — otherwise you start without this store's context. Returns facts ` +
|
|
34
|
+
`ranked by relevance with source attribution and confidence scores.\n\n` +
|
|
35
|
+
`Three fields come back. \`results\` is integrated knowledge: deduplicated, ` +
|
|
36
|
+
`reconciled against everything else known, entities resolved. Each result ` +
|
|
37
|
+
`carries speaker_role when the primary event is known (user, assistant, ` +
|
|
38
|
+
`system, or tool) and speaker when the transcript named the person — ` +
|
|
39
|
+
`who uttered it, not who it is about. \`pending\` ` +
|
|
40
|
+
`is what was captured recently and not yet consolidated — real, and ` +
|
|
41
|
+
`usually the most recent thing you were told, but not yet checked against ` +
|
|
42
|
+
`existing knowledge, so it may duplicate or contradict a fact in results. ` +
|
|
43
|
+
`Trust results first; use pending to avoid forgetting something you were ` +
|
|
44
|
+
`told minutes ago. \`episodes\` is filled only when results are empty: a ` +
|
|
45
|
+
`short raw-log window around a keyword hit in the copied transcript, not ` +
|
|
46
|
+
`yet extracted. It is not knowledge of the same standing — do not report ` +
|
|
47
|
+
`it as an integrated fact.
|
|
48
|
+
|
|
49
|
+
` +
|
|
50
|
+
`When semantic search is enabled, \`results\` also matches on meaning, so a ` +
|
|
51
|
+
`query can surface a fact that shares none of its words. \`pending\` and ` +
|
|
52
|
+
`\`episodes\` never do — they are keyword-only. A just-captured fact is ` +
|
|
53
|
+
`findable by its own words but not yet by a paraphrase of them.` +
|
|
54
|
+
(bitemporal
|
|
55
|
+
? `\n\nThis store records when the system retracted a belief. When you ` +
|
|
56
|
+
`need what it believed at a past instant — not what is true now, and ` +
|
|
57
|
+
`not when a fact was true in the world — pass as_of_system_time as an ` +
|
|
58
|
+
`ISO 8601 instant. Superseded facts the system still held then come ` +
|
|
59
|
+
`back; facts it learned afterwards do not. Omit it for current ` +
|
|
60
|
+
`knowledge, which is almost always what you want. Queries before this ` +
|
|
61
|
+
`store switched on that recording may be incomplete; the response then ` +
|
|
62
|
+
`includes system_time_warning.`
|
|
63
|
+
: "");
|
|
64
|
+
const searchSchema = {
|
|
65
|
+
query: z.string().describe("What to search for"),
|
|
66
|
+
domain: z
|
|
67
|
+
.string()
|
|
68
|
+
.optional()
|
|
69
|
+
.describe(`Prioritise a domain. Domains are whatever this store uses — they are ` +
|
|
70
|
+
`not a fixed list, so call get_schemas to see them rather than ` +
|
|
71
|
+
`guessing. This biases ranking rather than filtering: facts in the ` +
|
|
72
|
+
`domain are surfaced and rank higher, but a strong match elsewhere ` +
|
|
73
|
+
`still appears. Domains are assigned by a classifier and are ` +
|
|
74
|
+
`approximate, so a hard filter would hide a fact filed under a ` +
|
|
75
|
+
`near-synonym. Omit it to search everything.`),
|
|
76
|
+
...(bitemporal
|
|
77
|
+
? {
|
|
78
|
+
as_of_system_time: z
|
|
79
|
+
.string()
|
|
80
|
+
.optional()
|
|
81
|
+
.describe(`ISO 8601 instant (e.g. 2026-03-15T12:00:00Z). Returns facts ` +
|
|
82
|
+
`the system believed at that instant, including ones it later ` +
|
|
83
|
+
`superseded. Omit for current knowledge.`),
|
|
84
|
+
}
|
|
85
|
+
: {}),
|
|
86
|
+
};
|
|
87
|
+
server.tool("search_knowledge", searchDescription, searchSchema, async (args) => {
|
|
88
|
+
await beforeRead?.();
|
|
89
|
+
const rawAsOf = bitemporal &&
|
|
90
|
+
"as_of_system_time" in args &&
|
|
91
|
+
typeof args.as_of_system_time === "string"
|
|
92
|
+
? args.as_of_system_time
|
|
93
|
+
: undefined;
|
|
94
|
+
const asOfSystemTime = rawAsOf ? parseSystemTime(rawAsOf) : undefined;
|
|
95
|
+
const response = await searchWithProvider(db, args.query, embedding, {
|
|
96
|
+
domain: args.domain,
|
|
97
|
+
tuning,
|
|
98
|
+
asOfSystemTime,
|
|
99
|
+
interlocutor,
|
|
100
|
+
});
|
|
101
|
+
if (asOfSystemTime) {
|
|
102
|
+
response.system_time_warning = systemTimeWarning(asOfSystemTime, temporal?.bitemporal_since ?? null);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
content: [
|
|
106
|
+
{ type: "text", text: JSON.stringify(response) },
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
// get_profile and get_preferences were removed. Both selected a fixed domain
|
|
111
|
+
// ('profile', 'preferences') on an engine that ships no vocabulary — so they
|
|
112
|
+
// returned nothing for any store that does not happen to use those names, and
|
|
113
|
+
// named the engine after one use case. Their value is served universally
|
|
114
|
+
// elsewhere: the memory://briefing resource is the cue-less session-start
|
|
115
|
+
// digest (importance-ranked, vocabulary-agnostic), and search_knowledge /
|
|
116
|
+
// get_context / get_entity answer on-demand. "The user's preferences" is just
|
|
117
|
+
// search_knowledge with a domain the store actually uses.
|
|
118
|
+
// -----------------------------------------------------------------
|
|
119
|
+
// get_entity
|
|
120
|
+
// -----------------------------------------------------------------
|
|
121
|
+
server.tool("get_entity", `Get everything known about a named thing — who or what it is, the facts ` +
|
|
122
|
+
`about it, and how it connects to other things.\n\n` +
|
|
123
|
+
`A "thing" is any subject this store holds knowledge about: a person, an ` +
|
|
124
|
+
`organisation, a project, a place, a product, a system — whatever the ` +
|
|
125
|
+
`store is used for. This is the "tell me about X" tool.\n\n` +
|
|
126
|
+
`Call this WHENEVER a named thing is mentioned or alluded to and knowing ` +
|
|
127
|
+
`it would improve your answer — including indirect references like "my ` +
|
|
128
|
+
`manager", "the Helsinki office", "the payments service". Call it before ` +
|
|
129
|
+
`advising on anything involving that thing, and before asking who or what ` +
|
|
130
|
+
`something is — you may already know.\n\n` +
|
|
131
|
+
`Facts come back most relevant first, each flagged with is_subject. True ` +
|
|
132
|
+
`means the fact is ABOUT this thing; false means it only mentions it. ` +
|
|
133
|
+
`Treat the difference as real when you answer: "Alex's transfer was ` +
|
|
134
|
+
`approved by Robin" is worth knowing when asked about Robin, but it is a ` +
|
|
135
|
+
`fact about Alex, and reporting it as something you know about Robin ` +
|
|
136
|
+
`would be wrong. Other relationship values are the same kind of role — ` +
|
|
137
|
+
`this entity's part in this fact, free text, not a directed graph edge. ` +
|
|
138
|
+
`Do not infer who did what to whom from the wording.\n\n` +
|
|
139
|
+
`If several entity rows share that name under different types (the ` +
|
|
140
|
+
`extractor labelled one thing two ways), facts from all of them come ` +
|
|
141
|
+
`back. Hyphens, underscores, and stray punctuation count as the same ` +
|
|
142
|
+
`letters only when that does not join two names already stored as ` +
|
|
143
|
+
`separate rows. If this store has no entity by that name, facts that ` +
|
|
144
|
+
`mention the wording still come back (is_subject false) rather than an ` +
|
|
145
|
+
`empty miss. found is whether an entity row exists, not whether ` +
|
|
146
|
+
`anything is known.`, {
|
|
147
|
+
name: z
|
|
148
|
+
.string()
|
|
149
|
+
.describe("The thing's name. Resolve an indirect reference to a name first " +
|
|
150
|
+
"if you can (e.g. via get_context or a prior fact)."),
|
|
151
|
+
type: z
|
|
152
|
+
.string()
|
|
153
|
+
.optional()
|
|
154
|
+
.describe("Optional type filter, only for disambiguation when one name refers " +
|
|
155
|
+
"to two different things (a person and a project both called " +
|
|
156
|
+
"'Mercury'). Types are whatever this store uses — omit it to match " +
|
|
157
|
+
"any type, which is almost always what you want."),
|
|
158
|
+
}, async (args) => {
|
|
159
|
+
await beforeRead?.();
|
|
160
|
+
// Type omitted matches any entity type. The engine ships no entity
|
|
161
|
+
// vocabulary either — a corporate store's subjects are systems and
|
|
162
|
+
// suppliers, not people — so defaulting to a fixed type would make most
|
|
163
|
+
// subjects invisible to the one tool meant to find them.
|
|
164
|
+
const lookup = await lookupNamedSubject(db, args.name, args.type);
|
|
165
|
+
return {
|
|
166
|
+
content: [
|
|
167
|
+
{
|
|
168
|
+
type: "text",
|
|
169
|
+
text: JSON.stringify({
|
|
170
|
+
found: lookup.found,
|
|
171
|
+
name: lookup.name,
|
|
172
|
+
entity: lookup.entity,
|
|
173
|
+
entities: lookup.entities,
|
|
174
|
+
facts: lookup.facts,
|
|
175
|
+
relationships: lookup.relationships,
|
|
176
|
+
type_missed: lookup.type_missed,
|
|
177
|
+
}),
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
// -----------------------------------------------------------------
|
|
183
|
+
// get_context
|
|
184
|
+
// -----------------------------------------------------------------
|
|
185
|
+
server.tool("get_context", `Get everything known about a topic, combining search with entity ` +
|
|
186
|
+
`relationship traversal. More comprehensive than search_knowledge — it ` +
|
|
187
|
+
`follows entity connections outward: from a named subject to the things ` +
|
|
188
|
+
`it relates to, and the facts about those in turn.\n\n` +
|
|
189
|
+
`Call this when you need the COMPLETE picture of a topic, subject, or ` +
|
|
190
|
+
`domain rather than a specific fact — planning something involving a ` +
|
|
191
|
+
`person, project or system, catching up on a subject, or answering an ` +
|
|
192
|
+
`open-ended question about any of them.\n\n` +
|
|
193
|
+
`Prefer search_knowledge when you want one fact fast; prefer this when ` +
|
|
194
|
+
`missing a connection would make your answer wrong.`, {
|
|
195
|
+
topic: z
|
|
196
|
+
.string()
|
|
197
|
+
.describe("Topic, person, project, or domain to explore"),
|
|
198
|
+
}, async (args) => {
|
|
199
|
+
await beforeRead?.();
|
|
200
|
+
// Union type-split nodes. First-match would hide edges attached to a
|
|
201
|
+
// sibling type (stg_orders as model vs table).
|
|
202
|
+
const ctx = await getTopicContext(db, args.topic, interlocutor);
|
|
203
|
+
return {
|
|
204
|
+
content: [
|
|
205
|
+
{
|
|
206
|
+
type: "text",
|
|
207
|
+
text: JSON.stringify({
|
|
208
|
+
search: ctx.search,
|
|
209
|
+
entity: ctx.entity,
|
|
210
|
+
entities: ctx.entities,
|
|
211
|
+
connected: ctx.connected,
|
|
212
|
+
}),
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
// -----------------------------------------------------------------
|
|
218
|
+
// get_schemas
|
|
219
|
+
// -----------------------------------------------------------------
|
|
220
|
+
server.tool("get_schemas", `List the knowledge domains this user's memory actually uses, and their ` +
|
|
221
|
+
`subdomains. The set is not fixed — beyond the core domains it grows to ` +
|
|
222
|
+
`fit the user, so it is worth asking rather than assuming.\n\n` +
|
|
223
|
+
`Call this before filtering a search by domain, before choosing a ` +
|
|
224
|
+
`domain_hint for capture_fact, or when you want to know how this user's ` +
|
|
225
|
+
`knowledge is organised. Rarely needed mid-conversation — search_knowledge ` +
|
|
226
|
+
`and get_context work without it.`, {}, async () => {
|
|
227
|
+
const domains = await getDomains(db);
|
|
228
|
+
return {
|
|
229
|
+
content: [
|
|
230
|
+
{
|
|
231
|
+
type: "text",
|
|
232
|
+
text: JSON.stringify({ domains }),
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
// -----------------------------------------------------------------
|
|
238
|
+
// get_stats
|
|
239
|
+
// -----------------------------------------------------------------
|
|
240
|
+
server.tool("get_stats", `Get knowledge base statistics — how many facts are currently true, how ` +
|
|
241
|
+
`many are held in total including superseded history, entity and domain ` +
|
|
242
|
+
`counts, how facts are distributed across domains, and how much raw log ` +
|
|
243
|
+
`can be reclaimed.\n\n` +
|
|
244
|
+
`Call this when the user asks what you know or remember about them, how ` +
|
|
245
|
+
`much you have stored, or whether their memory is working. This answers ` +
|
|
246
|
+
`"how much do you know", not "what do you know" — use search_knowledge, ` +
|
|
247
|
+
`get_entity or get_context for actual recall.
|
|
248
|
+
|
|
249
|
+
` +
|
|
250
|
+
`\`embeddings\` reports semantic-search coverage per model. An empty list ` +
|
|
251
|
+
`means this store searches by keyword only, which is the default. A count ` +
|
|
252
|
+
`well below the current fact count means some facts are findable by ` +
|
|
253
|
+
`wording but not by meaning — worth mentioning if the user asks why ` +
|
|
254
|
+
`something was not recalled.\n\n` +
|
|
255
|
+
`\`extract.unextracted_events\` is how many transcript lines extract has ` +
|
|
256
|
+
`not examined. \`pending_facts\` is I not yet integrated. ` +
|
|
257
|
+
`A large unextracted count with a healthy fact count means capture is ` +
|
|
258
|
+
`writing D that extract has not examined.\n\n` +
|
|
259
|
+
`\`intelligence\` is billed consolidation spend (calls, tokens, elapsed), ` +
|
|
260
|
+
`broken down by stage and provider for the last 24 hours, all time, and ` +
|
|
261
|
+
`the last few runs. Embeddings are not this number — they are a separate ` +
|
|
262
|
+
`API. Token fields are omitted when the provider did not report them, ` +
|
|
263
|
+
`not shown as zero.\n\n` +
|
|
264
|
+
`\`token_budget\` is remaining room under optional ` +
|
|
265
|
+
`intelligence.token_budget caps (per billed provider, rolling hour / day / ` +
|
|
266
|
+
`week / month). Unset means unlimited. Over the cap, consolidate skips ` +
|
|
267
|
+
`extract, holds the watermark, and does not fall back to the heuristic.`, {}, async () => {
|
|
268
|
+
// Shared with `facthouse stats` so the tool and the CLI can't disagree.
|
|
269
|
+
return {
|
|
270
|
+
content: [
|
|
271
|
+
{ type: "text", text: JSON.stringify(await getStats(db)) },
|
|
272
|
+
],
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=read-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-tools.js","sourceRoot":"","sources":["../../src/tools/read-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E,MAAM,UAAU,iBAAiB,CAC/B,MAAiB,EACjB,EAAM;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Z,oEAAoE;IACpE,MAAM,CAAC,IAAI,CACT,WAAW,EACX,yEAAyE;QACvE,yEAAyE;QACzE,yEAAyE;QACzE,uBAAuB;QACvB,yEAAyE;QACzE,yEAAyE;QACzE,yEAAyE;QACzE;;CAEL;QACK,2EAA2E;QAC3E,2EAA2E;QAC3E,qEAAqE;QACrE,qEAAqE;QACrE,iCAAiC;QACjC,0EAA0E;QAC1E,2DAA2D;QAC3D,uEAAuE;QACvE,8CAA8C;QAC9C,2EAA2E;QAC3E,yEAAyE;QACzE,0EAA0E;QAC1E,uEAAuE;QACvE,wBAAwB;QACxB,oDAAoD;QACpD,4EAA4E;QAC5E,wEAAwE;QACxE,wEAAwE,EAC1E,EAAE,EACF,KAAK,IAAI,EAAE;QACT,wEAAwE;QACxE,OAAO;YACL,OAAO,EAAE;gBACP,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE;aACpE;SACF,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP resources — automatically-loaded context.
|
|
3
|
+
*
|
|
4
|
+
* Tools require the AI to decide to call them; resources are loaded by the
|
|
5
|
+
* client without a decision. That is the whole point of these two: a session
|
|
6
|
+
* starts with the user's context present, rather than depending on the model
|
|
7
|
+
* remembering to go looking for it.
|
|
8
|
+
*
|
|
9
|
+
* Both are read-only computed views over the same database the read tools
|
|
10
|
+
* query. Their lead section is the store's highest-importance facts — a
|
|
11
|
+
* cue-less, always-available digest of what matters most, ranked by the store's
|
|
12
|
+
* own importance calibration rather than by a fixed domain. That is what makes
|
|
13
|
+
* them work for any store: a personal one surfaces identity and medical facts,
|
|
14
|
+
* a corporate one surfaces incidents and clients, with no engine-side opinion.
|
|
15
|
+
*
|
|
16
|
+
* Content is markdown rather than JSON: it is injected into a model's context,
|
|
17
|
+
* so it should read as prose, not as a payload to parse.
|
|
18
|
+
*/
|
|
19
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
20
|
+
import type { Db } from "../db/connection.js";
|
|
21
|
+
export declare const PROFILE_URI = "memory://profile";
|
|
22
|
+
export declare const BRIEFING_URI = "memory://briefing";
|
|
23
|
+
/**
|
|
24
|
+
* How a tools-only client gets the briefing.
|
|
25
|
+
*
|
|
26
|
+
* `memory://briefing` is the right artefact. Cursor, Windsurf, and Grok never
|
|
27
|
+
* fetch resources, so a session starts with no working set. This string is the
|
|
28
|
+
* one instruction that closes the gap: MCP initialize `instructions`, and the
|
|
29
|
+
* lead of `get_session_context`. Do not paste a third copy.
|
|
30
|
+
*/
|
|
31
|
+
export declare const SESSION_BOOTSTRAP_INSTRUCTIONS: string;
|
|
32
|
+
/** Tool description for get_session_context. Lead is SESSION_BOOTSTRAP_INSTRUCTIONS. */
|
|
33
|
+
export declare function sessionContextDescription(): string;
|
|
34
|
+
/** `memory://profile` — the store's most important facts as markdown. */
|
|
35
|
+
export declare function buildProfile(db: Db): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* `memory://briefing` — the store's key facts, the last consolidation's
|
|
38
|
+
* narrative, open threads, and recent changes. The one view an assistant should
|
|
39
|
+
* read at the start of a session.
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildBriefing(db: Db): Promise<string>;
|
|
42
|
+
export interface ResourceNotifier {
|
|
43
|
+
/** Tell subscribed clients the resource content changed. Never throws. */
|
|
44
|
+
notifyUpdated(): void;
|
|
45
|
+
/** Currently-subscribed URIs. Exposed for tests. */
|
|
46
|
+
subscriptions(): ReadonlySet<string>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Register both resources and the subscribe/unsubscribe handlers.
|
|
50
|
+
*
|
|
51
|
+
* MUST be called before `server.connect()` — registering a resource registers
|
|
52
|
+
* the `resources` capability, and capabilities cannot change after a transport
|
|
53
|
+
* is attached.
|
|
54
|
+
*
|
|
55
|
+
* The SDK ships `resources/subscribe` as a type but implements no handler, so
|
|
56
|
+
* a client calling it would get MethodNotFound. We implement it here: content
|
|
57
|
+
* changes on consolidation, and `resources/updated` is the notification that
|
|
58
|
+
* says so. `resources/list_changed` would be wrong — the list of resources
|
|
59
|
+
* never changes, only what they contain.
|
|
60
|
+
*/
|
|
61
|
+
export declare function registerResources(server: McpServer, db: Db, beforeRead?: () => Promise<void>): ResourceNotifier;
|
|
62
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/tools/resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AAa9C,eAAO,MAAM,WAAW,qBAAqB,CAAC;AAC9C,eAAO,MAAM,YAAY,sBAAsB,CAAC;AAEhD;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,QAIvB,CAAC;AAErB,wFAAwF;AACxF,wBAAgB,yBAAyB,IAAI,MAAM,CAOlD;AAuDD,yEAAyE;AACzE,wBAAsB,YAAY,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAM1D;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAsD3D;AAMD,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,aAAa,IAAI,IAAI,CAAC;IACtB,oDAAoD;IACpD,aAAa,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;CACtC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,EACjB,EAAE,EAAE,EAAE,EACN,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAC/B,gBAAgB,CA+DlB"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP resources — automatically-loaded context.
|
|
3
|
+
*
|
|
4
|
+
* Tools require the AI to decide to call them; resources are loaded by the
|
|
5
|
+
* client without a decision. That is the whole point of these two: a session
|
|
6
|
+
* starts with the user's context present, rather than depending on the model
|
|
7
|
+
* remembering to go looking for it.
|
|
8
|
+
*
|
|
9
|
+
* Both are read-only computed views over the same database the read tools
|
|
10
|
+
* query. Their lead section is the store's highest-importance facts — a
|
|
11
|
+
* cue-less, always-available digest of what matters most, ranked by the store's
|
|
12
|
+
* own importance calibration rather than by a fixed domain. That is what makes
|
|
13
|
+
* them work for any store: a personal one surfaces identity and medical facts,
|
|
14
|
+
* a corporate one surfaces incidents and clients, with no engine-side opinion.
|
|
15
|
+
*
|
|
16
|
+
* Content is markdown rather than JSON: it is injected into a model's context,
|
|
17
|
+
* so it should read as prose, not as a payload to parse.
|
|
18
|
+
*/
|
|
19
|
+
import { SubscribeRequestSchema, UnsubscribeRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
20
|
+
import { structuredSearch } from "../search/index.js";
|
|
21
|
+
import { getLatestSummarised } from "../db/consolidations.js";
|
|
22
|
+
import { keyFacts } from "../search/key-facts.js";
|
|
23
|
+
import { formatDiskBudget } from "../db/disk-budget.js";
|
|
24
|
+
import { getStats } from "../db/stats.js";
|
|
25
|
+
import { unexaminedEventCount } from "../db/extract-watermarks.js";
|
|
26
|
+
import { EXTRACT_CAP_EVENTS } from "../intelligence/steps.js";
|
|
27
|
+
// The URI keeps its historical name so existing subscribers do not break; the
|
|
28
|
+
// content is no longer domain-scoped. It is the store's key facts, whatever the
|
|
29
|
+
// store is about.
|
|
30
|
+
export const PROFILE_URI = "memory://profile";
|
|
31
|
+
export const BRIEFING_URI = "memory://briefing";
|
|
32
|
+
/**
|
|
33
|
+
* How a tools-only client gets the briefing.
|
|
34
|
+
*
|
|
35
|
+
* `memory://briefing` is the right artefact. Cursor, Windsurf, and Grok never
|
|
36
|
+
* fetch resources, so a session starts with no working set. This string is the
|
|
37
|
+
* one instruction that closes the gap: MCP initialize `instructions`, and the
|
|
38
|
+
* lead of `get_session_context`. Do not paste a third copy.
|
|
39
|
+
*/
|
|
40
|
+
export const SESSION_BOOTSTRAP_INSTRUCTIONS = "At the start of every conversation, before answering, call get_session_context " +
|
|
41
|
+
"unless you already loaded the memory://briefing resource. That call returns the " +
|
|
42
|
+
"same working briefing the resource would have injected. Tools-only clients never " +
|
|
43
|
+
"fetch resources.";
|
|
44
|
+
/** Tool description for get_session_context. Lead is SESSION_BOOTSTRAP_INSTRUCTIONS. */
|
|
45
|
+
export function sessionContextDescription() {
|
|
46
|
+
return (SESSION_BOOTSTRAP_INSTRUCTIONS +
|
|
47
|
+
"\n\nAlso returns facts captured in this session that have not been " +
|
|
48
|
+
"consolidated yet. Call it before re-capturing a fact you may have already " +
|
|
49
|
+
"stored this session.");
|
|
50
|
+
}
|
|
51
|
+
/** Keep the briefing near the ~100 line budget it is specified to fit in. */
|
|
52
|
+
const KEY_FACTS_LIMIT = 15;
|
|
53
|
+
const RECENT_LIMIT = 20;
|
|
54
|
+
const THREADS_LIMIT = 5;
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Content
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
function bullet(f) {
|
|
59
|
+
return `- ${f.content}`;
|
|
60
|
+
}
|
|
61
|
+
async function pendingEventCount(db) {
|
|
62
|
+
return unexaminedEventCount(db);
|
|
63
|
+
}
|
|
64
|
+
async function consolidationRunCount(db) {
|
|
65
|
+
return (await db.prepare(`SELECT COUNT(*) AS n FROM consolidations`).get()).n;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Next step when the store has no integrated facts. The profile is loaded by
|
|
69
|
+
* the MCP client for the assistant — name the `consolidate` tool, not only
|
|
70
|
+
* the CLI. Pending count is since the last watermark; extract is capped per
|
|
71
|
+
* run, so a 5_000-event backfill is told it takes several runs or `--all`.
|
|
72
|
+
*/
|
|
73
|
+
async function emptyStoreNextStep(db) {
|
|
74
|
+
const pending = await pendingEventCount(db);
|
|
75
|
+
if (pending > 0) {
|
|
76
|
+
const capNote = pending <= EXTRACT_CAP_EVENTS
|
|
77
|
+
? " A later MCP session start will take this leftover."
|
|
78
|
+
: ` More than ${EXTRACT_CAP_EVENTS} events wait; each run extracts that many oldest first, or run \`facthouse consolidate --all\`.`;
|
|
79
|
+
return ("Nothing captured yet. Conversation events are waiting — call the " +
|
|
80
|
+
"`consolidate` tool, or run `facthouse consolidate` from the CLI." +
|
|
81
|
+
capNote);
|
|
82
|
+
}
|
|
83
|
+
if ((await consolidationRunCount(db)) > 0) {
|
|
84
|
+
return ("Nothing captured yet. Events were processed but produced no facts — " +
|
|
85
|
+
"heuristic extraction does not read transcripts. Use the claude CLI, then " +
|
|
86
|
+
"call `consolidate` (or `facthouse consolidate`).");
|
|
87
|
+
}
|
|
88
|
+
return ("Nothing captured yet. If this store has a named source, run " +
|
|
89
|
+
"`facthouse consolidate` from the CLI, or call `consolidate`.");
|
|
90
|
+
}
|
|
91
|
+
/** `memory://profile` — the store's most important facts as markdown. */
|
|
92
|
+
export async function buildProfile(db) {
|
|
93
|
+
const facts = await keyFacts(db, 200);
|
|
94
|
+
if (facts.length === 0) {
|
|
95
|
+
return `# Key facts\n\n${await emptyStoreNextStep(db)}\n`;
|
|
96
|
+
}
|
|
97
|
+
return `# Key facts\n\n${facts.map(bullet).join("\n")}\n`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* `memory://briefing` — the store's key facts, the last consolidation's
|
|
101
|
+
* narrative, open threads, and recent changes. The one view an assistant should
|
|
102
|
+
* read at the start of a session.
|
|
103
|
+
*/
|
|
104
|
+
export async function buildBriefing(db) {
|
|
105
|
+
const parts = ["# Facthouse Briefing"];
|
|
106
|
+
const key = await keyFacts(db, KEY_FACTS_LIMIT);
|
|
107
|
+
parts.push("\n## Key facts\n", key.length
|
|
108
|
+
? key.map(bullet).join("\n")
|
|
109
|
+
: await emptyStoreNextStep(db));
|
|
110
|
+
// The narrative comes from the last run that actually produced one: a run
|
|
111
|
+
// records its row before the summary exists, and no-op runs never get one.
|
|
112
|
+
const last = await getLatestSummarised(db);
|
|
113
|
+
if (last?.summary) {
|
|
114
|
+
parts.push(`\n## Last consolidation\n`, last.summary);
|
|
115
|
+
}
|
|
116
|
+
const threads = (last?.open_threads ?? []).slice(0, THREADS_LIMIT);
|
|
117
|
+
if (threads.length) {
|
|
118
|
+
parts.push("\n## Open threads\n", threads.map((t) => `- ${t}`).join("\n"));
|
|
119
|
+
}
|
|
120
|
+
// No domain filter -> most recently integrated facts across every domain.
|
|
121
|
+
const recent = await structuredSearch(db, { limit: RECENT_LIMIT });
|
|
122
|
+
if (recent.length) {
|
|
123
|
+
parts.push("\n## Recent knowledge\n", recent
|
|
124
|
+
.map((f) => {
|
|
125
|
+
const scope = f.subdomain ? `${f.domain}/${f.subdomain}` : f.domain;
|
|
126
|
+
return `- **${scope}** — ${f.content}`;
|
|
127
|
+
})
|
|
128
|
+
.join("\n"));
|
|
129
|
+
}
|
|
130
|
+
if (!key.length && !last?.summary && !recent.length) {
|
|
131
|
+
parts.push("\nNo knowledge captured yet. Facts appear here once they have been captured and consolidated.");
|
|
132
|
+
}
|
|
133
|
+
const reclaim = (await getStats(db)).events.reclaimable;
|
|
134
|
+
if (reclaim.events > 0) {
|
|
135
|
+
parts.push(`\n${reclaim.events} raw events (${formatDiskBudget(reclaim.bytes)} of content) can be reclaimed with \`facthouse prune\`.`);
|
|
136
|
+
}
|
|
137
|
+
return parts.join("\n") + "\n";
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Register both resources and the subscribe/unsubscribe handlers.
|
|
141
|
+
*
|
|
142
|
+
* MUST be called before `server.connect()` — registering a resource registers
|
|
143
|
+
* the `resources` capability, and capabilities cannot change after a transport
|
|
144
|
+
* is attached.
|
|
145
|
+
*
|
|
146
|
+
* The SDK ships `resources/subscribe` as a type but implements no handler, so
|
|
147
|
+
* a client calling it would get MethodNotFound. We implement it here: content
|
|
148
|
+
* changes on consolidation, and `resources/updated` is the notification that
|
|
149
|
+
* says so. `resources/list_changed` would be wrong — the list of resources
|
|
150
|
+
* never changes, only what they contain.
|
|
151
|
+
*/
|
|
152
|
+
export function registerResources(server, db, beforeRead) {
|
|
153
|
+
const subscribed = new Set();
|
|
154
|
+
server.registerResource("profile", PROFILE_URI, {
|
|
155
|
+
title: "Key facts",
|
|
156
|
+
description: "The most important facts this store holds, ranked by importance — the fastest cue-less way to see what matters here. Loaded automatically; no tool call needed.",
|
|
157
|
+
mimeType: "text/markdown",
|
|
158
|
+
}, async (uri) => {
|
|
159
|
+
await beforeRead?.();
|
|
160
|
+
return {
|
|
161
|
+
contents: [
|
|
162
|
+
{ uri: uri.href, mimeType: "text/markdown", text: await buildProfile(db) },
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
server.registerResource("briefing", BRIEFING_URI, {
|
|
167
|
+
title: "Memory briefing",
|
|
168
|
+
description: "The most important things this store knows right now: its key facts, what was learned in the last consolidation, open threads, and recent knowledge. Read this first — it is the fastest way to load context at the start of a session.",
|
|
169
|
+
mimeType: "text/markdown",
|
|
170
|
+
}, async (uri) => {
|
|
171
|
+
await beforeRead?.();
|
|
172
|
+
return {
|
|
173
|
+
contents: [
|
|
174
|
+
{ uri: uri.href, mimeType: "text/markdown", text: await buildBriefing(db) },
|
|
175
|
+
],
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
server.server.setRequestHandler(SubscribeRequestSchema, async (req) => {
|
|
179
|
+
subscribed.add(req.params.uri);
|
|
180
|
+
return {};
|
|
181
|
+
});
|
|
182
|
+
server.server.setRequestHandler(UnsubscribeRequestSchema, async (req) => {
|
|
183
|
+
subscribed.delete(req.params.uri);
|
|
184
|
+
return {};
|
|
185
|
+
});
|
|
186
|
+
return {
|
|
187
|
+
notifyUpdated() {
|
|
188
|
+
for (const uri of subscribed) {
|
|
189
|
+
// Rejects when no transport is attached — consolidation can finish
|
|
190
|
+
// during shutdown. A failed notification must never surface as an
|
|
191
|
+
// error: the data is already committed, and the scheduler swallows
|
|
192
|
+
// throws anyway, which would hide a real one.
|
|
193
|
+
void server.server.sendResourceUpdated({ uri }).catch(() => undefined);
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
subscriptions: () => subscribed,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/tools/resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EACL,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,8EAA8E;AAC9E,gFAAgF;AAChF,kBAAkB;AAClB,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAC9C,MAAM,CAAC,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,8BAA8B,GACzC,iFAAiF;IACjF,kFAAkF;IAClF,mFAAmF;IACnF,kBAAkB,CAAC;AAErB,wFAAwF;AACxF,MAAM,UAA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AC,CAAC;IAEH,OAAO;QACL,aAAa;YACX,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;gBAC7B,mEAAmE;gBACnE,kEAAkE;gBAClE,mEAAmE;gBACnE,8CAA8C;gBAC9C,KAAK,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QACD,aAAa,EAAE,GAAG,EAAE,CAAC,UAAU;KAChC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session lifecycle management and event logging.
|
|
3
|
+
* Provides the log_event MCP tool and the withEventLogging wrapper.
|
|
4
|
+
*/
|
|
5
|
+
import type { Db } from "../db/connection.js";
|
|
6
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
|
+
import type { Session, SessionEvent } from "../types/data.js";
|
|
8
|
+
export interface SessionManager {
|
|
9
|
+
/** The currently active session, or null if not yet started. */
|
|
10
|
+
getActiveSession(): Session | null;
|
|
11
|
+
/** Start a new session. Called from server.server.oninitialized. */
|
|
12
|
+
startSession(sourceTool: string | null, project: string | null): Promise<Session>;
|
|
13
|
+
/**
|
|
14
|
+
* Log an event in the current session.
|
|
15
|
+
* Throws if no session has been started.
|
|
16
|
+
*/
|
|
17
|
+
logEvent(opts: {
|
|
18
|
+
event_type: SessionEvent["event_type"];
|
|
19
|
+
role: SessionEvent["role"];
|
|
20
|
+
content: string | null;
|
|
21
|
+
content_type?: SessionEvent["content_type"];
|
|
22
|
+
content_ref?: string | null;
|
|
23
|
+
metadata?: Record<string, unknown> | null;
|
|
24
|
+
/** Named participant when the transcript has one. Role stays the channel. */
|
|
25
|
+
speaker?: string | null;
|
|
26
|
+
}): Promise<SessionEvent>;
|
|
27
|
+
/** Register the log_event MCP tool on the server. */
|
|
28
|
+
registerTools(server: McpServer): void;
|
|
29
|
+
}
|
|
30
|
+
export declare function createSessionManager(db: Db, clientSessionId?: string | null): SessionManager;
|
|
31
|
+
/**
|
|
32
|
+
* Register read tools for session events on the server.
|
|
33
|
+
* Separated from SessionManager.registerTools so they can be wrapped
|
|
34
|
+
* with withEventLogging independently.
|
|
35
|
+
*/
|
|
36
|
+
export declare function registerSessionReadTools(server: McpServer, manager: SessionManager, db: Db, beforeRead?: () => Promise<void>): void;
|
|
37
|
+
type ToolCallback = (...args: any[]) => any;
|
|
38
|
+
/**
|
|
39
|
+
* Wrap a tool handler to automatically log tool_call and tool_result events.
|
|
40
|
+
* Do NOT apply this to the log_event tool itself (infinite recursion).
|
|
41
|
+
*/
|
|
42
|
+
export declare function withEventLogging(manager: SessionManager, toolName: string, handler: ToolCallback): ToolCallback;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=session-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/tools/session-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAa9D,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,gBAAgB,IAAI,OAAO,GAAG,IAAI,CAAC;IAEnC,oEAAoE;IACpE,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAElF;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE;QACb,UAAU,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;QACvC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;QAC3B,OA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