@rkarim08/sia 1.0.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/.claude-plugin/marketplace.json +35 -0
- package/.claude-plugin/plugin.json +27 -0
- package/.mcp.json +13 -0
- package/CLAUDE.md +226 -0
- package/LICENSE +202 -0
- package/PLUGIN_README.md +253 -0
- package/README.md +1013 -0
- package/agents/sia-changelog-writer.md +89 -0
- package/agents/sia-code-reviewer.md +86 -0
- package/agents/sia-conflict-resolver.md +100 -0
- package/agents/sia-convention-enforcer.md +69 -0
- package/agents/sia-debug.md +106 -0
- package/agents/sia-decision-reviewer.md +101 -0
- package/agents/sia-dependency-tracker.md +80 -0
- package/agents/sia-explain.md +126 -0
- package/agents/sia-feature.md +116 -0
- package/agents/sia-knowledge-capture.md +117 -0
- package/agents/sia-lead-architecture-advisor.md +93 -0
- package/agents/sia-lead-team-health.md +107 -0
- package/agents/sia-migration.md +100 -0
- package/agents/sia-onboarding.md +115 -0
- package/agents/sia-orientation.md +99 -0
- package/agents/sia-pm-briefing.md +106 -0
- package/agents/sia-pm-risk-advisor.md +82 -0
- package/agents/sia-qa-analyst.md +116 -0
- package/agents/sia-qa-regression-map.md +94 -0
- package/agents/sia-refactor.md +115 -0
- package/agents/sia-regression.md +112 -0
- package/agents/sia-security-audit.md +125 -0
- package/agents/sia-test-advisor.md +91 -0
- package/hooks/hooks.json +98 -0
- package/migrations/bridge/001_initial.sql +34 -0
- package/migrations/episodic/001_initial.sql +35 -0
- package/migrations/meta/001_initial.sql +68 -0
- package/migrations/semantic/001_initial.sql +292 -0
- package/migrations/semantic/002_ontology.sql +89 -0
- package/migrations/semantic/003_freshness.sql +63 -0
- package/migrations/semantic/004_v5_unified_schema.sql +194 -0
- package/migrations/semantic/005_backfill_event_kinds.sql +8 -0
- package/migrations/semantic/006_tree_sitter.sql +6 -0
- package/migrations/semantic/007_branch_snapshots.sql +22 -0
- package/package.json +110 -0
- package/scripts/branch-switch.sh +13 -0
- package/scripts/build-wasm-grammars.sh +81 -0
- package/scripts/post-compact.sh +8 -0
- package/scripts/post-tool-use.sh +10 -0
- package/scripts/pre-compact.sh +8 -0
- package/scripts/session-end.sh +8 -0
- package/scripts/session-start.sh +8 -0
- package/scripts/start-mcp.ts +45 -0
- package/scripts/stop-hook.sh +8 -0
- package/scripts/user-prompt-submit.sh +8 -0
- package/scripts/viz-server.ts +152 -0
- package/skills/sia-brainstorm/SKILL.md +156 -0
- package/skills/sia-brainstorm/scripts/frame-template.html +214 -0
- package/skills/sia-brainstorm/scripts/helper.js +95 -0
- package/skills/sia-brainstorm/scripts/server.cjs +338 -0
- package/skills/sia-brainstorm/scripts/start-server.sh +153 -0
- package/skills/sia-brainstorm/scripts/stop-server.sh +55 -0
- package/skills/sia-brainstorm/spec-document-reviewer-prompt.md +49 -0
- package/skills/sia-brainstorm/visual-companion.md +286 -0
- package/skills/sia-capture/SKILL.md +64 -0
- package/skills/sia-compare/SKILL.md +33 -0
- package/skills/sia-conflicts/SKILL.md +38 -0
- package/skills/sia-debug-workflow/SKILL.md +120 -0
- package/skills/sia-debug-workflow/root-cause-tracing.md +70 -0
- package/skills/sia-debug-workflow/scripts/find-polluter.sh +64 -0
- package/skills/sia-debug-workflow/temporal-investigation.md +72 -0
- package/skills/sia-digest/SKILL.md +23 -0
- package/skills/sia-dispatch/SKILL.md +69 -0
- package/skills/sia-dispatch/agent-task-template.md +99 -0
- package/skills/sia-doctor/SKILL.md +39 -0
- package/skills/sia-execute/SKILL.md +70 -0
- package/skills/sia-execute-plan/SKILL.md +85 -0
- package/skills/sia-export-import/SKILL.md +49 -0
- package/skills/sia-export-knowledge/SKILL.md +46 -0
- package/skills/sia-finish/SKILL.md +100 -0
- package/skills/sia-finish/pr-summary-template.md +54 -0
- package/skills/sia-freshness/SKILL.md +38 -0
- package/skills/sia-history/SKILL.md +42 -0
- package/skills/sia-impact/SKILL.md +70 -0
- package/skills/sia-index/SKILL.md +54 -0
- package/skills/sia-install/SKILL.md +39 -0
- package/skills/sia-lead-compliance/SKILL.md +16 -0
- package/skills/sia-lead-drift-report/SKILL.md +16 -0
- package/skills/sia-lead-knowledge-map/SKILL.md +16 -0
- package/skills/sia-learn/SKILL.md +58 -0
- package/skills/sia-plan/SKILL.md +68 -0
- package/skills/sia-plan/plan-reviewer-prompt.md +63 -0
- package/skills/sia-playbooks/SKILL.md +29 -0
- package/skills/sia-playbooks/reference-feature.md +100 -0
- package/skills/sia-playbooks/reference-flagging.md +50 -0
- package/skills/sia-playbooks/reference-orientation.md +92 -0
- package/skills/sia-playbooks/reference-regression.md +115 -0
- package/skills/sia-playbooks/reference-review.md +64 -0
- package/skills/sia-playbooks/reference-tools.md +239 -0
- package/skills/sia-pm-decision-log/SKILL.md +28 -0
- package/skills/sia-pm-risk-dashboard/SKILL.md +24 -0
- package/skills/sia-pm-sprint-summary/SKILL.md +27 -0
- package/skills/sia-prune/SKILL.md +45 -0
- package/skills/sia-qa-coverage/SKILL.md +28 -0
- package/skills/sia-qa-flaky/SKILL.md +20 -0
- package/skills/sia-qa-report/SKILL.md +26 -0
- package/skills/sia-reindex/SKILL.md +30 -0
- package/skills/sia-review-respond/SKILL.md +88 -0
- package/skills/sia-review-respond/pushback-patterns.md +90 -0
- package/skills/sia-search/SKILL.md +47 -0
- package/skills/sia-setup/SKILL.md +82 -0
- package/skills/sia-setup/setup-checklist.md +97 -0
- package/skills/sia-stats/SKILL.md +36 -0
- package/skills/sia-status/SKILL.md +44 -0
- package/skills/sia-sync/SKILL.md +46 -0
- package/skills/sia-team/SKILL.md +64 -0
- package/skills/sia-test/SKILL.md +92 -0
- package/skills/sia-test/testing-anti-patterns.md +104 -0
- package/skills/sia-tour/SKILL.md +29 -0
- package/skills/sia-upgrade/SKILL.md +43 -0
- package/skills/sia-verify/SKILL.md +81 -0
- package/skills/sia-visualize/SKILL.md +28 -0
- package/skills/sia-visualize-live/SKILL.md +55 -0
- package/skills/sia-visualize-live/scripts/graph-template.html +389 -0
- package/skills/sia-visualize-live/scripts/start-visualizer.sh +161 -0
- package/skills/sia-visualize-live/scripts/stop-visualizer.sh +55 -0
- package/skills/sia-visualize-live/scripts/visualizer-server.cjs +264 -0
- package/skills/sia-workspace/SKILL.md +57 -0
- package/src/agent/claude-md-template-flagging.md +219 -0
- package/src/agent/claude-md-template.md +213 -0
- package/src/agent/modules/sia-feature.md +100 -0
- package/src/agent/modules/sia-flagging.md +50 -0
- package/src/agent/modules/sia-orientation.md +92 -0
- package/src/agent/modules/sia-regression.md +115 -0
- package/src/agent/modules/sia-review.md +64 -0
- package/src/agent/modules/sia-tools.md +239 -0
- package/src/ast/extractors/c-include.ts +189 -0
- package/src/ast/extractors/csharp-project.ts +260 -0
- package/src/ast/extractors/prisma-schema.ts +44 -0
- package/src/ast/extractors/project-manifest.ts +111 -0
- package/src/ast/extractors/sql-schema.ts +67 -0
- package/src/ast/extractors/tier-a.ts +423 -0
- package/src/ast/extractors/tier-b.ts +289 -0
- package/src/ast/extractors/tier-dispatch.ts +247 -0
- package/src/ast/index-worker.ts +108 -0
- package/src/ast/indexer.ts +484 -0
- package/src/ast/languages.ts +408 -0
- package/src/ast/pagerank-builder.ts +125 -0
- package/src/ast/path-utils.ts +137 -0
- package/src/ast/tree-sitter/backends/native.ts +57 -0
- package/src/ast/tree-sitter/backends/wasm.ts +39 -0
- package/src/ast/tree-sitter/call-walker.ts +44 -0
- package/src/ast/tree-sitter/edit-computer.ts +55 -0
- package/src/ast/tree-sitter/query-runner.ts +46 -0
- package/src/ast/tree-sitter/service.ts +174 -0
- package/src/ast/tree-sitter/tree-cache.ts +39 -0
- package/src/ast/tree-sitter/types.ts +79 -0
- package/src/ast/watcher.ts +322 -0
- package/src/capture/chunker.ts +169 -0
- package/src/capture/consolidate.ts +127 -0
- package/src/capture/edge-inferrer.ts +161 -0
- package/src/capture/embedder.ts +166 -0
- package/src/capture/embedding-cache.ts +73 -0
- package/src/capture/flag-processor.ts +64 -0
- package/src/capture/hook.ts +67 -0
- package/src/capture/pipeline.ts +450 -0
- package/src/capture/prompts/consolidate.ts +25 -0
- package/src/capture/prompts/edge-infer.ts +29 -0
- package/src/capture/prompts/extract-flagged.ts +36 -0
- package/src/capture/prompts/extract.ts +42 -0
- package/src/capture/tokenizer.ts +147 -0
- package/src/capture/track-a-ast.ts +93 -0
- package/src/capture/track-b-llm.ts +149 -0
- package/src/capture/types.ts +64 -0
- package/src/cli/commands/community.ts +137 -0
- package/src/cli/commands/compare.ts +123 -0
- package/src/cli/commands/conflicts.ts +41 -0
- package/src/cli/commands/digest.ts +197 -0
- package/src/cli/commands/disable-flagging.ts +34 -0
- package/src/cli/commands/doctor.ts +240 -0
- package/src/cli/commands/download-model.ts +161 -0
- package/src/cli/commands/enable-flagging.ts +34 -0
- package/src/cli/commands/export-knowledge.ts +208 -0
- package/src/cli/commands/export.ts +85 -0
- package/src/cli/commands/freshness.ts +164 -0
- package/src/cli/commands/graph.ts +51 -0
- package/src/cli/commands/history.ts +139 -0
- package/src/cli/commands/import.ts +335 -0
- package/src/cli/commands/install.ts +156 -0
- package/src/cli/commands/lead-report.ts +241 -0
- package/src/cli/commands/learn.ts +321 -0
- package/src/cli/commands/pm-report.ts +413 -0
- package/src/cli/commands/prune.ts +75 -0
- package/src/cli/commands/qa-report.ts +278 -0
- package/src/cli/commands/reindex.ts +104 -0
- package/src/cli/commands/rollback.ts +70 -0
- package/src/cli/commands/search.ts +103 -0
- package/src/cli/commands/server.ts +91 -0
- package/src/cli/commands/share.ts +33 -0
- package/src/cli/commands/stats.ts +79 -0
- package/src/cli/commands/status.ts +176 -0
- package/src/cli/commands/sync.ts +96 -0
- package/src/cli/commands/team.ts +118 -0
- package/src/cli/commands/tour.ts +157 -0
- package/src/cli/commands/visualize-live.ts +162 -0
- package/src/cli/commands/workspace.ts +117 -0
- package/src/cli/index.ts +424 -0
- package/src/cli/learn-progress.ts +87 -0
- package/src/community/detection-bridge.ts +344 -0
- package/src/community/leiden.ts +462 -0
- package/src/community/raptor.ts +210 -0
- package/src/community/scheduler.ts +74 -0
- package/src/community/summarize.ts +115 -0
- package/src/decay/archiver.ts +73 -0
- package/src/decay/bridge-orphan-cleanup.ts +212 -0
- package/src/decay/consolidation-sweep.ts +112 -0
- package/src/decay/decay.ts +116 -0
- package/src/decay/deep-validator.ts +62 -0
- package/src/decay/episodic-promoter.ts +132 -0
- package/src/decay/maintenance-scheduler.ts +326 -0
- package/src/decay/scheduler.ts +6 -0
- package/src/decay/session-sweeper.ts +79 -0
- package/src/decay/types.ts +17 -0
- package/src/freshness/confidence-decay.ts +122 -0
- package/src/freshness/cuckoo-filter.ts +176 -0
- package/src/freshness/deep-validation.ts +345 -0
- package/src/freshness/dirty-tracker.ts +237 -0
- package/src/freshness/file-watcher-layer.ts +119 -0
- package/src/freshness/firewall.ts +64 -0
- package/src/freshness/git-reconcile-layer.ts +161 -0
- package/src/freshness/inverted-index.ts +158 -0
- package/src/freshness/stale-read-layer.ts +222 -0
- package/src/graph/audit.ts +69 -0
- package/src/graph/bridge-db.ts +141 -0
- package/src/graph/communities.ts +195 -0
- package/src/graph/db-interface.ts +259 -0
- package/src/graph/edges.ts +163 -0
- package/src/graph/entities.ts +327 -0
- package/src/graph/episodic-db.ts +113 -0
- package/src/graph/flags.ts +31 -0
- package/src/graph/meta-db.ts +200 -0
- package/src/graph/semantic-db.ts +101 -0
- package/src/graph/session-resume.ts +56 -0
- package/src/graph/snapshots.ts +342 -0
- package/src/graph/staging.ts +151 -0
- package/src/graph/types.ts +128 -0
- package/src/hooks/adapters/claude-code.ts +21 -0
- package/src/hooks/adapters/cline.ts +43 -0
- package/src/hooks/adapters/cursor.ts +65 -0
- package/src/hooks/adapters/generic.ts +12 -0
- package/src/hooks/agent-detect.ts +34 -0
- package/src/hooks/claude-md-directives.ts +32 -0
- package/src/hooks/event-router.ts +182 -0
- package/src/hooks/extractors/pattern-detector.ts +111 -0
- package/src/hooks/handlers/post-compact.ts +30 -0
- package/src/hooks/handlers/post-tool-use.ts +403 -0
- package/src/hooks/handlers/pre-compact.ts +100 -0
- package/src/hooks/handlers/session-end.ts +47 -0
- package/src/hooks/handlers/session-start.ts +154 -0
- package/src/hooks/handlers/stop.ts +128 -0
- package/src/hooks/handlers/user-prompt-submit.ts +68 -0
- package/src/hooks/plugin-branch-switch.ts +68 -0
- package/src/hooks/plugin-common.ts +47 -0
- package/src/hooks/plugin-post-compact.ts +28 -0
- package/src/hooks/plugin-post-tool-use.ts +38 -0
- package/src/hooks/plugin-pre-compact.ts +37 -0
- package/src/hooks/plugin-session-end.ts +37 -0
- package/src/hooks/plugin-session-start.ts +75 -0
- package/src/hooks/plugin-stop.ts +61 -0
- package/src/hooks/plugin-user-prompt-submit.ts +47 -0
- package/src/hooks/types.ts +43 -0
- package/src/knowledge/discovery.ts +238 -0
- package/src/knowledge/external-refs.ts +98 -0
- package/src/knowledge/freshness.ts +221 -0
- package/src/knowledge/ingest.ts +330 -0
- package/src/knowledge/markdown-export.ts +229 -0
- package/src/knowledge/markdown-import.ts +359 -0
- package/src/knowledge/patterns.ts +74 -0
- package/src/knowledge/templates.ts +307 -0
- package/src/llm/ai-sdk-adapter.ts +46 -0
- package/src/llm/config.ts +88 -0
- package/src/llm/cost-tracker.ts +110 -0
- package/src/llm/prompts/extraction.ts +55 -0
- package/src/llm/prompts/summarization.ts +36 -0
- package/src/llm/prompts/validation.ts +37 -0
- package/src/llm/provider-registry.ts +68 -0
- package/src/llm/reliability.ts +179 -0
- package/src/llm/schemas.ts +52 -0
- package/src/mcp/freshness-annotator.ts +69 -0
- package/src/mcp/server.ts +949 -0
- package/src/mcp/tools/sia-ast-query.ts +225 -0
- package/src/mcp/tools/sia-at-time.ts +151 -0
- package/src/mcp/tools/sia-backlinks.ts +87 -0
- package/src/mcp/tools/sia-batch-execute.ts +169 -0
- package/src/mcp/tools/sia-by-file.ts +89 -0
- package/src/mcp/tools/sia-community.ts +113 -0
- package/src/mcp/tools/sia-doctor.ts +73 -0
- package/src/mcp/tools/sia-execute-file.ts +122 -0
- package/src/mcp/tools/sia-execute.ts +104 -0
- package/src/mcp/tools/sia-expand.ts +158 -0
- package/src/mcp/tools/sia-fetch-and-index.ts +241 -0
- package/src/mcp/tools/sia-flag.ts +65 -0
- package/src/mcp/tools/sia-index.ts +111 -0
- package/src/mcp/tools/sia-note.ts +134 -0
- package/src/mcp/tools/sia-search.ts +105 -0
- package/src/mcp/tools/sia-stats.ts +63 -0
- package/src/mcp/tools/sia-sync-status.ts +44 -0
- package/src/mcp/tools/sia-upgrade.ts +247 -0
- package/src/mcp/truncate.ts +231 -0
- package/src/native/bridge.ts +167 -0
- package/src/native/fallback-ast-diff.ts +144 -0
- package/src/native/fallback-graph.ts +325 -0
- package/src/ontology/constraints.ts +56 -0
- package/src/ontology/errors.ts +8 -0
- package/src/ontology/middleware.ts +266 -0
- package/src/retrieval/bm25-search.ts +151 -0
- package/src/retrieval/context-assembly.ts +76 -0
- package/src/retrieval/graph-traversal.ts +168 -0
- package/src/retrieval/pagerank.ts +40 -0
- package/src/retrieval/query-classifier.ts +106 -0
- package/src/retrieval/reranker.ts +156 -0
- package/src/retrieval/search.ts +236 -0
- package/src/retrieval/throttle.ts +102 -0
- package/src/retrieval/vector-search.ts +203 -0
- package/src/retrieval/workspace-search.ts +130 -0
- package/src/sandbox/context-mode.ts +285 -0
- package/src/sandbox/credential-pass.ts +55 -0
- package/src/sandbox/executor.ts +235 -0
- package/src/security/pattern-detector.ts +127 -0
- package/src/security/rule-of-two.ts +50 -0
- package/src/security/sanitize.ts +46 -0
- package/src/security/semantic-consistency.ts +93 -0
- package/src/security/staging-promoter.ts +154 -0
- package/src/shared/config.ts +302 -0
- package/src/shared/diagnostics.ts +210 -0
- package/src/shared/errors.ts +48 -0
- package/src/shared/git-utils.ts +143 -0
- package/src/shared/llm-client.ts +120 -0
- package/src/shared/logger.ts +99 -0
- package/src/shared/types.ts +79 -0
- package/src/sync/client.ts +43 -0
- package/src/sync/conflict.ts +106 -0
- package/src/sync/dedup.ts +183 -0
- package/src/sync/hlc.ts +117 -0
- package/src/sync/keychain.ts +144 -0
- package/src/sync/pull.ts +232 -0
- package/src/sync/push.ts +131 -0
- package/src/types/chokidar.d.ts +23 -0
- package/src/visualization/graph-renderer.ts +312 -0
- package/src/visualization/subgraph-extract.ts +208 -0
- package/src/visualization/views/community-clusters.ts +246 -0
- package/src/visualization/views/dependency-map.ts +189 -0
- package/src/visualization/views/graph-explorer.ts +364 -0
- package/src/visualization/views/timeline.ts +247 -0
- package/src/workspace/api-contracts.ts +226 -0
- package/src/workspace/cross-repo.ts +61 -0
- package/src/workspace/detector.ts +190 -0
- package/src/workspace/manifest.ts +141 -0
|
@@ -0,0 +1,949 @@
|
|
|
1
|
+
// Module: server — MCP server registering all Sia tool handlers
|
|
2
|
+
//
|
|
3
|
+
// Read-heavy against graph.db. Write paths: session_flags (sia_flag),
|
|
4
|
+
// graph entities/edges (sia_note), sandbox results (sia_execute*).
|
|
5
|
+
|
|
6
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import type { Embedder } from "@/capture/embedder";
|
|
10
|
+
import type { SiaDb } from "@/graph/db-interface";
|
|
11
|
+
import {
|
|
12
|
+
handleSiaAstQuery,
|
|
13
|
+
type SiaAstQueryInput as SiaAstQueryHandlerInput,
|
|
14
|
+
} from "@/mcp/tools/sia-ast-query";
|
|
15
|
+
import { handleSiaAtTime } from "@/mcp/tools/sia-at-time";
|
|
16
|
+
import { handleSiaBacklinks } from "@/mcp/tools/sia-backlinks";
|
|
17
|
+
import { handleSiaBatchExecute } from "@/mcp/tools/sia-batch-execute";
|
|
18
|
+
import { handleSiaByFile } from "@/mcp/tools/sia-by-file";
|
|
19
|
+
import { handleSiaCommunity } from "@/mcp/tools/sia-community";
|
|
20
|
+
import { handleSiaDoctor } from "@/mcp/tools/sia-doctor";
|
|
21
|
+
import { handleSiaExecute } from "@/mcp/tools/sia-execute";
|
|
22
|
+
import { handleSiaExecuteFile } from "@/mcp/tools/sia-execute-file";
|
|
23
|
+
import { handleSiaExpand } from "@/mcp/tools/sia-expand";
|
|
24
|
+
import { handleSiaFetchAndIndex } from "@/mcp/tools/sia-fetch-and-index";
|
|
25
|
+
import { handleSiaFlag } from "@/mcp/tools/sia-flag";
|
|
26
|
+
import { handleSiaIndex } from "@/mcp/tools/sia-index";
|
|
27
|
+
import { handleSiaNote } from "@/mcp/tools/sia-note";
|
|
28
|
+
import { handleSiaSearch } from "@/mcp/tools/sia-search";
|
|
29
|
+
import { handleSiaStats } from "@/mcp/tools/sia-stats";
|
|
30
|
+
import { handleSiaSyncStatus } from "@/mcp/tools/sia-sync-status";
|
|
31
|
+
import { handleSiaUpgrade } from "@/mcp/tools/sia-upgrade";
|
|
32
|
+
import { truncateResponse } from "@/mcp/truncate";
|
|
33
|
+
import { ProgressiveThrottle } from "@/retrieval/throttle";
|
|
34
|
+
import type { SiaConfig } from "@/shared/config";
|
|
35
|
+
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// Zod input schemas for every tool — exported so tests (and future handler
|
|
38
|
+
// modules) can reference them directly.
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
export const SiaSearchInput = z.object({
|
|
42
|
+
query: z.string(),
|
|
43
|
+
task_type: z.enum(["orientation", "feature", "bug-fix", "regression", "review"]).optional(),
|
|
44
|
+
node_types: z.array(z.string()).optional(),
|
|
45
|
+
package_path: z.string().optional(),
|
|
46
|
+
workspace: z.boolean().optional(),
|
|
47
|
+
paranoid: z.boolean().optional(),
|
|
48
|
+
limit: z.number().optional(),
|
|
49
|
+
include_provenance: z.boolean().optional(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const SiaByFileInput = z.object({
|
|
53
|
+
file_path: z.string(),
|
|
54
|
+
workspace: z.boolean().optional(),
|
|
55
|
+
limit: z.number().optional(),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const SiaExpandInput = z.object({
|
|
59
|
+
entity_id: z.string(),
|
|
60
|
+
depth: z.union([z.literal(1), z.literal(2), z.literal(3)]).optional(),
|
|
61
|
+
edge_types: z.array(z.string()).optional(),
|
|
62
|
+
include_cross_repo: z.boolean().optional(),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const SiaCommunityInput = z.object({
|
|
66
|
+
query: z.string().optional(),
|
|
67
|
+
entity_id: z.string().optional(),
|
|
68
|
+
level: z.union([z.literal(0), z.literal(1), z.literal(2)]).optional(),
|
|
69
|
+
package_path: z.string().optional(),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const SiaAtTimeInput = z.object({
|
|
73
|
+
as_of: z.string(),
|
|
74
|
+
entity_types: z.array(z.string()).optional(),
|
|
75
|
+
tags: z.array(z.string()).optional(),
|
|
76
|
+
limit: z.number().optional(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export const SiaFlagInput = z.object({
|
|
80
|
+
reason: z.string(),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export const SiaBacklinksInput = z.object({
|
|
84
|
+
node_id: z.string(),
|
|
85
|
+
edge_types: z.array(z.string()).optional(),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const SiaNoteInput = z.object({
|
|
89
|
+
kind: z.enum(["Decision", "Convention", "Bug", "Solution", "Concept"]),
|
|
90
|
+
name: z.string(),
|
|
91
|
+
content: z.string(),
|
|
92
|
+
tags: z.array(z.string()).optional(),
|
|
93
|
+
relates_to: z.array(z.string()).optional(),
|
|
94
|
+
supersedes: z.string().optional(),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export const SiaExecuteInput = z.object({
|
|
98
|
+
code: z.string(),
|
|
99
|
+
language: z.string().optional(),
|
|
100
|
+
intent: z.string().optional(),
|
|
101
|
+
timeout: z.number().optional(),
|
|
102
|
+
env: z.record(z.string(), z.string()).optional(),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const SiaExecuteFileInput = z.object({
|
|
106
|
+
file_path: z.string(),
|
|
107
|
+
language: z.string().optional(),
|
|
108
|
+
command: z.string().optional(),
|
|
109
|
+
intent: z.string().optional(),
|
|
110
|
+
timeout: z.number().optional(),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export const SiaIndexInput = z.object({
|
|
114
|
+
content: z.string(),
|
|
115
|
+
source: z.string().optional(),
|
|
116
|
+
tags: z.array(z.string()).optional(),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
export const SiaBatchExecuteInput = z.object({
|
|
120
|
+
operations: z.array(
|
|
121
|
+
z.object({
|
|
122
|
+
type: z.enum(["execute", "search"]),
|
|
123
|
+
code: z.string().optional(),
|
|
124
|
+
language: z.string().optional(),
|
|
125
|
+
query: z.string().optional(),
|
|
126
|
+
intent: z.string().optional(),
|
|
127
|
+
}),
|
|
128
|
+
),
|
|
129
|
+
timeout_per_op: z.number().optional(),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export const SiaFetchAndIndexInput = z.object({
|
|
133
|
+
url: z.string().url(),
|
|
134
|
+
intent: z.string().optional(),
|
|
135
|
+
tags: z.array(z.string()).optional(),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
export const SiaStatsInput = z.object({
|
|
139
|
+
include_session: z.boolean().optional(),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export const SiaDoctorInput = z.object({
|
|
143
|
+
checks: z
|
|
144
|
+
.array(z.enum(["runtimes", "hooks", "fts5", "vss", "onnx", "graph_integrity", "all"]))
|
|
145
|
+
.optional(),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
export const SiaSyncStatusInput = z.object({});
|
|
149
|
+
|
|
150
|
+
export const SiaUpgradeInput = z.object({
|
|
151
|
+
target_version: z.string().optional(),
|
|
152
|
+
dry_run: z.boolean().optional(),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export const SiaAstQueryInput = z.object({
|
|
156
|
+
file_path: z.string(),
|
|
157
|
+
query_type: z.enum(["symbols", "imports", "calls"]),
|
|
158
|
+
max_results: z.number().optional(),
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
export const SiaSnapshotListInput = z.object({});
|
|
162
|
+
|
|
163
|
+
export const SiaSnapshotRestoreInput = z.object({
|
|
164
|
+
branch_name: z.string(),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export const SiaSnapshotPruneInput = z.object({
|
|
168
|
+
branch_names: z.array(z.string()),
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
// Tool names — single source of truth
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
|
|
175
|
+
export const TOOL_NAMES = [
|
|
176
|
+
"sia_search",
|
|
177
|
+
"sia_by_file",
|
|
178
|
+
"sia_expand",
|
|
179
|
+
"sia_community",
|
|
180
|
+
"sia_at_time",
|
|
181
|
+
"sia_flag",
|
|
182
|
+
"sia_backlinks",
|
|
183
|
+
"sia_note",
|
|
184
|
+
"sia_execute",
|
|
185
|
+
"sia_execute_file",
|
|
186
|
+
"sia_index",
|
|
187
|
+
"sia_batch_execute",
|
|
188
|
+
"sia_fetch_and_index",
|
|
189
|
+
"sia_stats",
|
|
190
|
+
"sia_doctor",
|
|
191
|
+
"sia_upgrade",
|
|
192
|
+
"sia_sync_status",
|
|
193
|
+
"sia_ast_query",
|
|
194
|
+
"sia_snapshot_list",
|
|
195
|
+
"sia_snapshot_restore",
|
|
196
|
+
"sia_snapshot_prune",
|
|
197
|
+
] as const;
|
|
198
|
+
|
|
199
|
+
export type SiaToolName = (typeof TOOL_NAMES)[number];
|
|
200
|
+
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
// McpServerDeps — dependencies for wiring real tool handlers
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
|
|
205
|
+
export interface McpServerDeps {
|
|
206
|
+
graphDb: SiaDb;
|
|
207
|
+
bridgeDb: SiaDb | null;
|
|
208
|
+
metaDb: SiaDb | null;
|
|
209
|
+
embedder: Embedder | null;
|
|
210
|
+
config: SiaConfig;
|
|
211
|
+
sessionId: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
// safeToolCall — wrap a handler call with try-catch, returning structured error
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
|
|
218
|
+
/** Wrap a handler call with try-catch, truncation, and server-side error logging. */
|
|
219
|
+
async function safeToolCall<T>(
|
|
220
|
+
toolName: string,
|
|
221
|
+
fn: () => Promise<T>,
|
|
222
|
+
maxChars?: number,
|
|
223
|
+
): Promise<{ content: { type: "text"; text: string }[]; isError?: boolean }> {
|
|
224
|
+
try {
|
|
225
|
+
const result = await fn();
|
|
226
|
+
return {
|
|
227
|
+
content: [
|
|
228
|
+
{ type: "text" as const, text: JSON.stringify(truncateResponse(result, maxChars)) },
|
|
229
|
+
],
|
|
230
|
+
};
|
|
231
|
+
} catch (err) {
|
|
232
|
+
console.error(`[sia] ${toolName} error:`, err);
|
|
233
|
+
return {
|
|
234
|
+
content: [
|
|
235
|
+
{
|
|
236
|
+
type: "text" as const,
|
|
237
|
+
text: JSON.stringify({
|
|
238
|
+
error: `${toolName} failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
239
|
+
}),
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
isError: true,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
// createMcpServer — builds and returns a configured McpServer
|
|
249
|
+
// ---------------------------------------------------------------------------
|
|
250
|
+
|
|
251
|
+
export function createMcpServer(deps?: McpServerDeps): McpServer {
|
|
252
|
+
const server = new McpServer({ name: "sia", version: "0.1.0" });
|
|
253
|
+
// workingMemoryTokenBudget is token-denominated; multiply by ~4 to approximate
|
|
254
|
+
// a character budget for JSON truncation (1 token ≈ 4 chars in JSON output).
|
|
255
|
+
const maxChars = deps ? deps.config.workingMemoryTokenBudget * 4 : undefined;
|
|
256
|
+
|
|
257
|
+
// --- sia_search --------------------------------------------------------
|
|
258
|
+
server.registerTool(
|
|
259
|
+
"sia_search",
|
|
260
|
+
{
|
|
261
|
+
description: "Semantic search across the Sia knowledge graph",
|
|
262
|
+
inputSchema: SiaSearchInput.shape,
|
|
263
|
+
annotations: { readOnlyHint: true },
|
|
264
|
+
},
|
|
265
|
+
async (args) => {
|
|
266
|
+
if (deps) {
|
|
267
|
+
return safeToolCall(
|
|
268
|
+
"sia_search",
|
|
269
|
+
() => handleSiaSearch(deps.graphDb, args, deps.embedder ?? undefined),
|
|
270
|
+
maxChars,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
content: [
|
|
275
|
+
{
|
|
276
|
+
type: "text" as const,
|
|
277
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
isError: true,
|
|
281
|
+
};
|
|
282
|
+
},
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// --- sia_by_file -------------------------------------------------------
|
|
286
|
+
server.registerTool(
|
|
287
|
+
"sia_by_file",
|
|
288
|
+
{
|
|
289
|
+
description: "Retrieve knowledge graph nodes associated with a file",
|
|
290
|
+
inputSchema: SiaByFileInput.shape,
|
|
291
|
+
annotations: { readOnlyHint: true },
|
|
292
|
+
},
|
|
293
|
+
async (args) => {
|
|
294
|
+
if (deps) {
|
|
295
|
+
return safeToolCall("sia_by_file", () => handleSiaByFile(deps.graphDb, args), maxChars);
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
content: [
|
|
299
|
+
{
|
|
300
|
+
type: "text" as const,
|
|
301
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
isError: true,
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
// --- sia_expand --------------------------------------------------------
|
|
310
|
+
server.registerTool(
|
|
311
|
+
"sia_expand",
|
|
312
|
+
{
|
|
313
|
+
description: "Expand an entity's neighbourhood in the knowledge graph",
|
|
314
|
+
inputSchema: SiaExpandInput.shape,
|
|
315
|
+
annotations: { readOnlyHint: true },
|
|
316
|
+
},
|
|
317
|
+
async (args) => {
|
|
318
|
+
if (deps) {
|
|
319
|
+
return safeToolCall("sia_expand", () => handleSiaExpand(deps.graphDb, args), maxChars);
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
content: [
|
|
323
|
+
{
|
|
324
|
+
type: "text" as const,
|
|
325
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
isError: true,
|
|
329
|
+
};
|
|
330
|
+
},
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
// --- sia_community -----------------------------------------------------
|
|
334
|
+
server.registerTool(
|
|
335
|
+
"sia_community",
|
|
336
|
+
{
|
|
337
|
+
description: "Retrieve community-level summaries from the knowledge graph",
|
|
338
|
+
inputSchema: SiaCommunityInput.shape,
|
|
339
|
+
annotations: { readOnlyHint: true },
|
|
340
|
+
},
|
|
341
|
+
async (args) => {
|
|
342
|
+
if (deps) {
|
|
343
|
+
return safeToolCall(
|
|
344
|
+
"sia_community",
|
|
345
|
+
() => handleSiaCommunity(deps.graphDb, args),
|
|
346
|
+
maxChars,
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
content: [
|
|
351
|
+
{
|
|
352
|
+
type: "text" as const,
|
|
353
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
isError: true,
|
|
357
|
+
};
|
|
358
|
+
},
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
// --- sia_at_time -------------------------------------------------------
|
|
362
|
+
server.registerTool(
|
|
363
|
+
"sia_at_time",
|
|
364
|
+
{
|
|
365
|
+
description: "Query the knowledge graph at a point in time",
|
|
366
|
+
inputSchema: SiaAtTimeInput.shape,
|
|
367
|
+
annotations: { readOnlyHint: true },
|
|
368
|
+
},
|
|
369
|
+
async (args) => {
|
|
370
|
+
if (deps) {
|
|
371
|
+
return safeToolCall("sia_at_time", () => handleSiaAtTime(deps.graphDb, args), maxChars);
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
content: [
|
|
375
|
+
{
|
|
376
|
+
type: "text" as const,
|
|
377
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
isError: true,
|
|
381
|
+
};
|
|
382
|
+
},
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
// --- sia_flag ----------------------------------------------------------
|
|
386
|
+
server.registerTool(
|
|
387
|
+
"sia_flag",
|
|
388
|
+
{
|
|
389
|
+
description: "Flag current session for human review (writes to session_flags only)",
|
|
390
|
+
inputSchema: SiaFlagInput.shape,
|
|
391
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
392
|
+
},
|
|
393
|
+
async (args) => {
|
|
394
|
+
if (deps) {
|
|
395
|
+
return safeToolCall(
|
|
396
|
+
"sia_flag",
|
|
397
|
+
() =>
|
|
398
|
+
handleSiaFlag(deps.graphDb, args, {
|
|
399
|
+
enableFlagging: deps.config.enableFlagging,
|
|
400
|
+
sessionId: deps.sessionId,
|
|
401
|
+
}),
|
|
402
|
+
maxChars,
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
return {
|
|
406
|
+
content: [
|
|
407
|
+
{
|
|
408
|
+
type: "text" as const,
|
|
409
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
isError: true,
|
|
413
|
+
};
|
|
414
|
+
},
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
// --- sia_backlinks -----------------------------------------------------
|
|
418
|
+
server.registerTool(
|
|
419
|
+
"sia_backlinks",
|
|
420
|
+
{
|
|
421
|
+
description: "Find all incoming edges (backlinks) to a knowledge graph node",
|
|
422
|
+
inputSchema: SiaBacklinksInput.shape,
|
|
423
|
+
annotations: { readOnlyHint: true },
|
|
424
|
+
},
|
|
425
|
+
async (args) => {
|
|
426
|
+
if (deps) {
|
|
427
|
+
return safeToolCall(
|
|
428
|
+
"sia_backlinks",
|
|
429
|
+
() => handleSiaBacklinks(deps.graphDb, args),
|
|
430
|
+
maxChars,
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
content: [
|
|
435
|
+
{
|
|
436
|
+
type: "text" as const,
|
|
437
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
isError: true,
|
|
441
|
+
};
|
|
442
|
+
},
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
// --- sia_note ----------------------------------------------------------
|
|
446
|
+
server.registerTool(
|
|
447
|
+
"sia_note",
|
|
448
|
+
{
|
|
449
|
+
description: "Create a developer-authored knowledge entry in the graph",
|
|
450
|
+
inputSchema: SiaNoteInput.shape,
|
|
451
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
452
|
+
},
|
|
453
|
+
async (args) => {
|
|
454
|
+
if (deps) {
|
|
455
|
+
return safeToolCall("sia_note", () => handleSiaNote(deps.graphDb, args), maxChars);
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
content: [
|
|
459
|
+
{
|
|
460
|
+
type: "text" as const,
|
|
461
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
462
|
+
},
|
|
463
|
+
],
|
|
464
|
+
isError: true,
|
|
465
|
+
};
|
|
466
|
+
},
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
// --- sia_execute -------------------------------------------------------
|
|
470
|
+
server.registerTool(
|
|
471
|
+
"sia_execute",
|
|
472
|
+
{
|
|
473
|
+
description: "Execute code in an isolated sandbox",
|
|
474
|
+
inputSchema: SiaExecuteInput.shape,
|
|
475
|
+
annotations: { readOnlyHint: false },
|
|
476
|
+
},
|
|
477
|
+
async (args) => {
|
|
478
|
+
if (deps) {
|
|
479
|
+
if (!deps.embedder) {
|
|
480
|
+
return {
|
|
481
|
+
content: [
|
|
482
|
+
{
|
|
483
|
+
type: "text" as const,
|
|
484
|
+
text: JSON.stringify({
|
|
485
|
+
error: "Embedder not available. Run sia_doctor to check ONNX status.",
|
|
486
|
+
}),
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
isError: true,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
const embedder = deps.embedder;
|
|
493
|
+
const throttle = new ProgressiveThrottle(deps.graphDb, {
|
|
494
|
+
normalMax: deps.config.throttleNormalMax,
|
|
495
|
+
reducedMax: deps.config.throttleReducedMax,
|
|
496
|
+
});
|
|
497
|
+
return safeToolCall(
|
|
498
|
+
"sia_execute",
|
|
499
|
+
() =>
|
|
500
|
+
handleSiaExecute(deps.graphDb, args, embedder, throttle, deps.sessionId, {
|
|
501
|
+
sandboxTimeoutMs: deps.config.sandboxTimeoutMs,
|
|
502
|
+
sandboxOutputMaxBytes: deps.config.sandboxOutputMaxBytes,
|
|
503
|
+
contextModeThreshold: deps.config.contextModeThreshold,
|
|
504
|
+
contextModeTopK: deps.config.contextModeTopK,
|
|
505
|
+
}),
|
|
506
|
+
maxChars,
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
content: [
|
|
511
|
+
{
|
|
512
|
+
type: "text" as const,
|
|
513
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
514
|
+
},
|
|
515
|
+
],
|
|
516
|
+
isError: true,
|
|
517
|
+
};
|
|
518
|
+
},
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
// --- sia_execute_file --------------------------------------------------
|
|
522
|
+
server.registerTool(
|
|
523
|
+
"sia_execute_file",
|
|
524
|
+
{
|
|
525
|
+
description: "Execute an existing file in a sandbox subprocess",
|
|
526
|
+
inputSchema: SiaExecuteFileInput.shape,
|
|
527
|
+
annotations: { readOnlyHint: false },
|
|
528
|
+
},
|
|
529
|
+
async (args) => {
|
|
530
|
+
if (deps) {
|
|
531
|
+
if (!deps.embedder) {
|
|
532
|
+
return {
|
|
533
|
+
content: [
|
|
534
|
+
{
|
|
535
|
+
type: "text" as const,
|
|
536
|
+
text: JSON.stringify({
|
|
537
|
+
error: "Embedder not available. Run sia_doctor to check ONNX status.",
|
|
538
|
+
}),
|
|
539
|
+
},
|
|
540
|
+
],
|
|
541
|
+
isError: true,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
const embedderFile = deps.embedder;
|
|
545
|
+
const throttle = new ProgressiveThrottle(deps.graphDb, {
|
|
546
|
+
normalMax: deps.config.throttleNormalMax,
|
|
547
|
+
reducedMax: deps.config.throttleReducedMax,
|
|
548
|
+
});
|
|
549
|
+
return safeToolCall(
|
|
550
|
+
"sia_execute_file",
|
|
551
|
+
() =>
|
|
552
|
+
handleSiaExecuteFile(deps.graphDb, args, embedderFile, throttle, deps.sessionId, {
|
|
553
|
+
sandboxTimeoutMs: deps.config.sandboxTimeoutMs,
|
|
554
|
+
sandboxOutputMaxBytes: deps.config.sandboxOutputMaxBytes,
|
|
555
|
+
contextModeThreshold: deps.config.contextModeThreshold,
|
|
556
|
+
contextModeTopK: deps.config.contextModeTopK,
|
|
557
|
+
}),
|
|
558
|
+
maxChars,
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
content: [
|
|
563
|
+
{
|
|
564
|
+
type: "text" as const,
|
|
565
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
566
|
+
},
|
|
567
|
+
],
|
|
568
|
+
isError: true,
|
|
569
|
+
};
|
|
570
|
+
},
|
|
571
|
+
);
|
|
572
|
+
|
|
573
|
+
// --- sia_index ---------------------------------------------------------
|
|
574
|
+
server.registerTool(
|
|
575
|
+
"sia_index",
|
|
576
|
+
{
|
|
577
|
+
description: "Index markdown/text content by chunking and scanning for entity references",
|
|
578
|
+
inputSchema: SiaIndexInput.shape,
|
|
579
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
580
|
+
},
|
|
581
|
+
async (args) => {
|
|
582
|
+
if (deps) {
|
|
583
|
+
if (!deps.embedder) {
|
|
584
|
+
return {
|
|
585
|
+
content: [
|
|
586
|
+
{
|
|
587
|
+
type: "text" as const,
|
|
588
|
+
text: JSON.stringify({
|
|
589
|
+
error: "Embedder not available. Run sia_doctor to check ONNX status.",
|
|
590
|
+
}),
|
|
591
|
+
},
|
|
592
|
+
],
|
|
593
|
+
isError: true,
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
const embedderIndex = deps.embedder;
|
|
597
|
+
return safeToolCall(
|
|
598
|
+
"sia_index",
|
|
599
|
+
() => handleSiaIndex(deps.graphDb, args, embedderIndex, deps.sessionId),
|
|
600
|
+
maxChars,
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
content: [
|
|
605
|
+
{
|
|
606
|
+
type: "text" as const,
|
|
607
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
608
|
+
},
|
|
609
|
+
],
|
|
610
|
+
isError: true,
|
|
611
|
+
};
|
|
612
|
+
},
|
|
613
|
+
);
|
|
614
|
+
|
|
615
|
+
// --- sia_batch_execute -------------------------------------------------
|
|
616
|
+
server.registerTool(
|
|
617
|
+
"sia_batch_execute",
|
|
618
|
+
{
|
|
619
|
+
description: "Execute multiple operations in one call with precedes edges",
|
|
620
|
+
inputSchema: SiaBatchExecuteInput.shape,
|
|
621
|
+
annotations: { readOnlyHint: false },
|
|
622
|
+
},
|
|
623
|
+
async (args) => {
|
|
624
|
+
if (deps) {
|
|
625
|
+
if (!deps.embedder) {
|
|
626
|
+
return {
|
|
627
|
+
content: [
|
|
628
|
+
{
|
|
629
|
+
type: "text" as const,
|
|
630
|
+
text: JSON.stringify({
|
|
631
|
+
error: "Embedder not available. Run sia_doctor to check ONNX status.",
|
|
632
|
+
}),
|
|
633
|
+
},
|
|
634
|
+
],
|
|
635
|
+
isError: true,
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
const embedderBatch = deps.embedder;
|
|
639
|
+
const throttle = new ProgressiveThrottle(deps.graphDb, {
|
|
640
|
+
normalMax: deps.config.throttleNormalMax,
|
|
641
|
+
reducedMax: deps.config.throttleReducedMax,
|
|
642
|
+
});
|
|
643
|
+
return safeToolCall(
|
|
644
|
+
"sia_batch_execute",
|
|
645
|
+
() =>
|
|
646
|
+
handleSiaBatchExecute(
|
|
647
|
+
deps.graphDb,
|
|
648
|
+
args as Parameters<typeof handleSiaBatchExecute>[1],
|
|
649
|
+
embedderBatch,
|
|
650
|
+
throttle,
|
|
651
|
+
deps.sessionId,
|
|
652
|
+
{ timeoutPerOp: deps.config.sandboxTimeoutMs },
|
|
653
|
+
),
|
|
654
|
+
maxChars,
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
return {
|
|
658
|
+
content: [
|
|
659
|
+
{
|
|
660
|
+
type: "text" as const,
|
|
661
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
662
|
+
},
|
|
663
|
+
],
|
|
664
|
+
isError: true,
|
|
665
|
+
};
|
|
666
|
+
},
|
|
667
|
+
);
|
|
668
|
+
|
|
669
|
+
// --- sia_fetch_and_index -----------------------------------------------
|
|
670
|
+
server.registerTool(
|
|
671
|
+
"sia_fetch_and_index",
|
|
672
|
+
{
|
|
673
|
+
description: "Fetch a URL, convert to markdown, and index via contentTypeChunker",
|
|
674
|
+
inputSchema: SiaFetchAndIndexInput.shape,
|
|
675
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
676
|
+
},
|
|
677
|
+
async (args) => {
|
|
678
|
+
if (deps) {
|
|
679
|
+
if (!deps.embedder) {
|
|
680
|
+
return {
|
|
681
|
+
content: [
|
|
682
|
+
{
|
|
683
|
+
type: "text" as const,
|
|
684
|
+
text: JSON.stringify({
|
|
685
|
+
error: "Embedder not available. Run sia_doctor to check ONNX status.",
|
|
686
|
+
}),
|
|
687
|
+
},
|
|
688
|
+
],
|
|
689
|
+
isError: true,
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
const embedderFetch = deps.embedder;
|
|
693
|
+
return safeToolCall(
|
|
694
|
+
"sia_fetch_and_index",
|
|
695
|
+
() => handleSiaFetchAndIndex(deps.graphDb, args, embedderFetch, deps.sessionId),
|
|
696
|
+
maxChars,
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
content: [
|
|
701
|
+
{
|
|
702
|
+
type: "text" as const,
|
|
703
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
704
|
+
},
|
|
705
|
+
],
|
|
706
|
+
isError: true,
|
|
707
|
+
};
|
|
708
|
+
},
|
|
709
|
+
);
|
|
710
|
+
|
|
711
|
+
// --- sia_stats ---------------------------------------------------------
|
|
712
|
+
server.registerTool(
|
|
713
|
+
"sia_stats",
|
|
714
|
+
{
|
|
715
|
+
description: "Return graph metrics: node/edge counts by type, optional session stats",
|
|
716
|
+
inputSchema: SiaStatsInput.shape,
|
|
717
|
+
annotations: { readOnlyHint: true },
|
|
718
|
+
},
|
|
719
|
+
async (args) => {
|
|
720
|
+
if (deps) {
|
|
721
|
+
return safeToolCall(
|
|
722
|
+
"sia_stats",
|
|
723
|
+
() => handleSiaStats(deps.graphDb, args, deps.sessionId),
|
|
724
|
+
maxChars,
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
return {
|
|
728
|
+
content: [
|
|
729
|
+
{
|
|
730
|
+
type: "text" as const,
|
|
731
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
732
|
+
},
|
|
733
|
+
],
|
|
734
|
+
isError: true,
|
|
735
|
+
};
|
|
736
|
+
},
|
|
737
|
+
);
|
|
738
|
+
|
|
739
|
+
// --- sia_doctor --------------------------------------------------------
|
|
740
|
+
server.registerTool(
|
|
741
|
+
"sia_doctor",
|
|
742
|
+
{
|
|
743
|
+
description: "Run diagnostic checks on the Sia installation",
|
|
744
|
+
inputSchema: SiaDoctorInput.shape,
|
|
745
|
+
annotations: { readOnlyHint: true },
|
|
746
|
+
},
|
|
747
|
+
async (args) => {
|
|
748
|
+
if (deps) {
|
|
749
|
+
return safeToolCall("sia_doctor", () => handleSiaDoctor(deps.graphDb, args), maxChars);
|
|
750
|
+
}
|
|
751
|
+
return {
|
|
752
|
+
content: [
|
|
753
|
+
{
|
|
754
|
+
type: "text" as const,
|
|
755
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
756
|
+
},
|
|
757
|
+
],
|
|
758
|
+
isError: true,
|
|
759
|
+
};
|
|
760
|
+
},
|
|
761
|
+
);
|
|
762
|
+
|
|
763
|
+
// --- sia_upgrade -------------------------------------------------------
|
|
764
|
+
server.registerTool(
|
|
765
|
+
"sia_upgrade",
|
|
766
|
+
{
|
|
767
|
+
description: "Self-update Sia to the latest version",
|
|
768
|
+
inputSchema: SiaUpgradeInput.shape,
|
|
769
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
770
|
+
},
|
|
771
|
+
async (args) => {
|
|
772
|
+
if (deps) {
|
|
773
|
+
return safeToolCall(
|
|
774
|
+
"sia_upgrade",
|
|
775
|
+
() =>
|
|
776
|
+
handleSiaUpgrade(deps.graphDb, args, {
|
|
777
|
+
upgradeReleaseUrl: deps.config.upgradeReleaseUrl ?? undefined,
|
|
778
|
+
}),
|
|
779
|
+
maxChars,
|
|
780
|
+
);
|
|
781
|
+
}
|
|
782
|
+
return {
|
|
783
|
+
content: [
|
|
784
|
+
{
|
|
785
|
+
type: "text" as const,
|
|
786
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
787
|
+
},
|
|
788
|
+
],
|
|
789
|
+
isError: true,
|
|
790
|
+
};
|
|
791
|
+
},
|
|
792
|
+
);
|
|
793
|
+
|
|
794
|
+
// --- sia_sync_status ---------------------------------------------------
|
|
795
|
+
server.registerTool(
|
|
796
|
+
"sia_sync_status",
|
|
797
|
+
{
|
|
798
|
+
description: "Check team sync configuration and connection status",
|
|
799
|
+
inputSchema: SiaSyncStatusInput.shape,
|
|
800
|
+
annotations: { readOnlyHint: true },
|
|
801
|
+
},
|
|
802
|
+
async () => {
|
|
803
|
+
return safeToolCall("sia_sync_status", () => handleSiaSyncStatus(), maxChars);
|
|
804
|
+
},
|
|
805
|
+
);
|
|
806
|
+
|
|
807
|
+
// --- sia_ast_query -----------------------------------------------------
|
|
808
|
+
server.registerTool(
|
|
809
|
+
"sia_ast_query",
|
|
810
|
+
{
|
|
811
|
+
description:
|
|
812
|
+
"Parse a file with tree-sitter and extract symbols, imports, or call relationships",
|
|
813
|
+
inputSchema: SiaAstQueryInput.shape,
|
|
814
|
+
annotations: { readOnlyHint: true },
|
|
815
|
+
},
|
|
816
|
+
async (args) => {
|
|
817
|
+
// sia_ast_query is stateless — no deps needed. It returns errors in-band
|
|
818
|
+
// via the error field rather than throwing, so we propagate isError manually.
|
|
819
|
+
const result = await handleSiaAstQuery(args as SiaAstQueryHandlerInput);
|
|
820
|
+
return {
|
|
821
|
+
content: [
|
|
822
|
+
{ type: "text" as const, text: JSON.stringify(truncateResponse(result, maxChars)) },
|
|
823
|
+
],
|
|
824
|
+
isError: result.error ? true : undefined,
|
|
825
|
+
};
|
|
826
|
+
},
|
|
827
|
+
);
|
|
828
|
+
|
|
829
|
+
// --- sia_snapshot_list --------------------------------------------------
|
|
830
|
+
server.registerTool(
|
|
831
|
+
"sia_snapshot_list",
|
|
832
|
+
{
|
|
833
|
+
description: "List all branch-keyed graph snapshots",
|
|
834
|
+
inputSchema: SiaSnapshotListInput.shape,
|
|
835
|
+
annotations: { readOnlyHint: true },
|
|
836
|
+
},
|
|
837
|
+
async () => {
|
|
838
|
+
if (deps) {
|
|
839
|
+
return safeToolCall(
|
|
840
|
+
"sia_snapshot_list",
|
|
841
|
+
async () => {
|
|
842
|
+
const { listBranchSnapshots } = await import("@/graph/snapshots");
|
|
843
|
+
const snapshots = await listBranchSnapshots(deps.graphDb);
|
|
844
|
+
return snapshots.map((s) => ({
|
|
845
|
+
branch_name: s.branch_name,
|
|
846
|
+
commit_hash: s.commit_hash,
|
|
847
|
+
node_count: s.node_count,
|
|
848
|
+
edge_count: s.edge_count,
|
|
849
|
+
updated_at: s.updated_at,
|
|
850
|
+
}));
|
|
851
|
+
},
|
|
852
|
+
maxChars,
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
return {
|
|
856
|
+
content: [
|
|
857
|
+
{
|
|
858
|
+
type: "text" as const,
|
|
859
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
860
|
+
},
|
|
861
|
+
],
|
|
862
|
+
isError: true,
|
|
863
|
+
};
|
|
864
|
+
},
|
|
865
|
+
);
|
|
866
|
+
|
|
867
|
+
// --- sia_snapshot_restore -----------------------------------------------
|
|
868
|
+
server.registerTool(
|
|
869
|
+
"sia_snapshot_restore",
|
|
870
|
+
{
|
|
871
|
+
description: "Restore the knowledge graph from a branch snapshot",
|
|
872
|
+
inputSchema: SiaSnapshotRestoreInput.shape,
|
|
873
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
874
|
+
},
|
|
875
|
+
async (args) => {
|
|
876
|
+
if (deps) {
|
|
877
|
+
return safeToolCall(
|
|
878
|
+
"sia_snapshot_restore",
|
|
879
|
+
async () => {
|
|
880
|
+
const { restoreBranchSnapshot } = await import("@/graph/snapshots");
|
|
881
|
+
const restored = await restoreBranchSnapshot(deps.graphDb, args.branch_name);
|
|
882
|
+
return { restored, branch_name: args.branch_name };
|
|
883
|
+
},
|
|
884
|
+
maxChars,
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
return {
|
|
888
|
+
content: [
|
|
889
|
+
{
|
|
890
|
+
type: "text" as const,
|
|
891
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
892
|
+
},
|
|
893
|
+
],
|
|
894
|
+
isError: true,
|
|
895
|
+
};
|
|
896
|
+
},
|
|
897
|
+
);
|
|
898
|
+
|
|
899
|
+
// --- sia_snapshot_prune -------------------------------------------------
|
|
900
|
+
server.registerTool(
|
|
901
|
+
"sia_snapshot_prune",
|
|
902
|
+
{
|
|
903
|
+
description: "Remove branch snapshots for specified branches",
|
|
904
|
+
inputSchema: SiaSnapshotPruneInput.shape,
|
|
905
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
906
|
+
},
|
|
907
|
+
async (args) => {
|
|
908
|
+
if (deps) {
|
|
909
|
+
return safeToolCall(
|
|
910
|
+
"sia_snapshot_prune",
|
|
911
|
+
async () => {
|
|
912
|
+
const { pruneBranchSnapshots } = await import("@/graph/snapshots");
|
|
913
|
+
const pruned = await pruneBranchSnapshots(deps.graphDb, args.branch_names);
|
|
914
|
+
return { pruned, branch_names: args.branch_names };
|
|
915
|
+
},
|
|
916
|
+
maxChars,
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
return {
|
|
920
|
+
content: [
|
|
921
|
+
{
|
|
922
|
+
type: "text" as const,
|
|
923
|
+
text: JSON.stringify({ error: "Sia server not initialized: missing dependencies" }),
|
|
924
|
+
},
|
|
925
|
+
],
|
|
926
|
+
isError: true,
|
|
927
|
+
};
|
|
928
|
+
},
|
|
929
|
+
);
|
|
930
|
+
|
|
931
|
+
return server;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// ---------------------------------------------------------------------------
|
|
935
|
+
// startServer — convenience entry-point for stdio mode
|
|
936
|
+
// ---------------------------------------------------------------------------
|
|
937
|
+
|
|
938
|
+
export async function startServer(deps?: McpServerDeps): Promise<McpServer> {
|
|
939
|
+
const server = createMcpServer(deps);
|
|
940
|
+
const transport = new StdioServerTransport();
|
|
941
|
+
try {
|
|
942
|
+
await server.connect(transport);
|
|
943
|
+
} catch (err) {
|
|
944
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
945
|
+
console.error(`[sia] Failed to start MCP server: ${message}`);
|
|
946
|
+
throw new Error(`Sia MCP server failed to connect via stdio: ${message}`);
|
|
947
|
+
}
|
|
948
|
+
return server;
|
|
949
|
+
}
|