feat(mcp): separate direct order queries from wiki tools

Add an opt-in business group with schema, template, guarded SQL, and status tools. Reuse existing order statistics through read-only SQLite connections without OpenCode or wiki retrieval.

Add tools set for switching enabled groups with one restart. Gate file diagnostics with file-assets and document business-only operation while retaining the independent Kingdee sync task.

Validation: 217 unit tests passed; business tool tests rerun after read-only annotations. Live authenticated MCP schema/status/template/SQL calls passed, ask_wiki was unavailable, uploads returned 404, and unauthenticated requests returned 401.
This commit is contained in:
Codex
2026-10-31 06:47:43 +00:00
parent 1133e2bf50
commit 6c451c3eb6
10 changed files with 500 additions and 44 deletions
+50
View File
@@ -14,6 +14,56 @@ Use `<vault>/_meta/business-facts.sqlite` for questions where markdown is the wr
The wiki remains the place for context: customer background, project history, sales notes, email-derived signals, and cross-linked narrative knowledge.
## Independent Business MCP
The `business` MCP tool group queries the synchronized SQLite database directly.
It does not start OpenCode, load `wiki-query`, read Wiki pages, or run Kingdee sync.
Clients interpret natural-language requests and call these tools:
| Tool | Purpose |
| --- | --- |
| `get_business_schema` | Tables, templates, parameters, configured internal-party defaults, and counting rules |
| `query_business_template` | Existing order, sales, customer/product/staff, and delivery-plan templates |
| `execute_business_sql` | Guarded SELECT fallback when no template fits |
| `get_business_status` | Data availability, stored order date range, and last successful sync |
To keep orders available while turning off all Wiki MCP capabilities:
```bash
scripts/mcp_service.sh tools set business
```
This saves `OBSIDIAN_MCP_ENABLED_TOOLS=business` and restarts the managed service
once, preserving the connection URL and bearer token. Reconnect clients to refresh
their tool list. `ask_wiki`, its job tools, file tools/resources, and ingest tools
and upload routes are absent. `get_mcp_capabilities` remains available.
Example tool arguments for `query_business_template`:
```json
{"template_name": "sales_amount", "params": {"year": 2026, "month": 6}}
```
Database connections use SQLite `mode=ro` and `query_only`; queries never initialize
or migrate the sync-owned database. Missing data returns an unavailable/error
response rather than silently creating an empty database. The existing independent
Kingdee timer continues to own updates. Database location defaults to
`<vault>/_meta/business-facts.sqlite`; `--business-db` or
`OBSIDIAN_MCP_BUSINESS_DB` (in the project `.env` or process environment) can select
another existing database without changing the file-asset index.
Templates load the operator's `OBSIDIAN_BUSINESS_INTERNAL_PARTIES`,
`OBSIDIAN_BUSINESS_INTERNAL_PARTY_IDS`, and `OBSIDIAN_BUSINESS_INCLUDE_INTERNAL_ORDERS`
settings. Clients cannot replace the internal-party lists; `include_internal_orders`
remains an explicit template option for internal-transfer audits. Guarded SQL keeps
the existing table/column restrictions and row limits, and must express the internal
transfer filter itself. All query results include `last_sync`, `is_stale`, and warnings.
The legacy `query` group still supports the combined OpenCode workflow when enabled.
For example, `scripts/mcp_service.sh tools set business file-assets query ingest`
enables both paths again. The groups are independently gated; this does not migrate
or duplicate the business database.
## Commands
```bash