server-instructions.mjs
56 lines 2.2 KB
Raw
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0 feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes… Human minor ⚠ breaking 12 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 1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882 fix(test): align Band B landing assertion with desktop MCP … Human 12 days ago