server-instructions.mjs
56 lines 2.2 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 days ago
1 /**
2 * MCP Phase G — scope hints for clients: initialize `instructions` + optional client roots logging.
3 * MCP "roots" are normally declared by the client; we document server filesystem scope in `instructions`.
4 */
5
6 import { pathToFileURL } from 'node:url';
7 import { loadConfig } from '../lib/config.mjs';
8
9 /**
10 * @param {string} absPath
11 * @returns {string}
12 */
13 export function fileUriForPath(absPath) {
14 return pathToFileURL(absPath).href;
15 }
16
17 /**
18 * @param {{ vault_path: string, data_dir: string, vaultList?: Array<{ id: string, path: string, label?: string }> }} config
19 * @returns {string}
20 */
21 export function buildKnowtationMcpInstructions(config) {
22 const vaultUri = fileUriForPath(config.vault_path);
23 const dataUri = fileUriForPath(config.data_dir);
24 const lines = [
25 'Knowtation is a personal knowledge assistant: it searches, reads, and writes Markdown notes in your vault, keeps a search index under your data directory, and exposes the same operations through MCP tools and resources as the CLI.',
26 'The server reads and writes only the configured vault paths and index data below—not arbitrary paths on your machine unless a tool is given an explicit vault-relative path inside that vault.',
27 '',
28 'Authoritative filesystem scope (add these as MCP client workspace roots when your client supports roots, so the model knows what this server is tied to):',
29 `- Vault (notes, media): ${vaultUri}`,
30 `- Data directory (index, sidecars): ${dataUri}`,
31 ];
32 if (config.vaultList && config.vaultList.length > 1) {
33 lines.push('', 'Configured vaults (multi-vault):');
34 for (const v of config.vaultList) {
35 const label = v.label || v.id;
36 lines.push(`- ${label} (${v.id}): ${fileUriForPath(v.path)}`);
37 }
38 }
39 return lines.join('\n');
40 }
41
42 /**
43 * @returns {string}
44 */
45 export function tryBuildKnowtationMcpInstructions() {
46 try {
47 return buildKnowtationMcpInstructions(loadConfig());
48 } catch (e) {
49 const msg = e instanceof Error ? e.message : String(e);
50 return [
51 'Knowtation MCP needs a valid vault before it can describe scope.',
52 'Set vault_path in config/local.yaml or KNOWTATION_VAULT_PATH, then restart the server.',
53 `Current error: ${msg}`,
54 ].join('\n');
55 }
56 }
File History 4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 30 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 49 days ago