@memoweft/mcp-server 0.1.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/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # @memoweft/mcp-server
2
+
3
+ [English](./README.md) · [简体中文](./README.zh-CN.md)
4
+
5
+ An [MCP](https://modelcontextprotocol.io) server that exposes a [MemoWeft](https://github.com/memoweft/memoweft) memory database as Model Context Protocol tools, so an external AI client (Claude Desktop, Cursor, or any MCP-capable host) can recall stored knowledge and record verbatim user messages.
6
+
7
+ This is an **external integration package**. It wraps MemoWeft's public Core facade (`createMemoWeftCore`) and does **not** re-implement any memory logic. It surfaces a deliberately narrow, mostly read-only tool surface.
8
+
9
+ ## Tools
10
+
11
+ ### Read (5)
12
+
13
+ | Tool | Core method | What it does |
14
+ |------|-------------|--------------|
15
+ | `memoweft_recall` | `core.recall` | Recall cognitions relevant to a query (with confidence + credibility). |
16
+ | `memoweft_list_cognitions` | `core.memory.listCognitions` | List all cognitions for a subject, with evidence links and effective confidence. |
17
+ | `memoweft_list_evidence` | `core.memory.listEvidence` | List all raw evidence (sources) for a subject. |
18
+ | `memoweft_list_events` | `core.memory.listEvents` | List all events for a subject, with the evidence ids each covers. |
19
+ | `memoweft_graph` | `core.graph.buildMemoryGraph` | Build a memory graph payload (nodes, edges, stats). |
20
+
21
+ ### Write (1, light)
22
+
23
+ | Tool | Core method | What it does |
24
+ |------|-------------|--------------|
25
+ | `memoweft_ingest_user_message` | `core.ingestUserMessage` | Store a **single verbatim user message** as spoken evidence. Does not update the profile, run consolidation, or grant any cloud-read authorization. |
26
+
27
+ ## SECURITY — this is an autonomous external call surface
28
+
29
+ MCP tools can be invoked **autonomously by an external AI client**, without a human approving each call. The tool surface here is chosen accordingly.
30
+
31
+ - **5 tools are read-only.** They never mutate memory.
32
+ - **1 tool is a light write** (`memoweft_ingest_user_message`): it records one raw user message as `spoken` evidence. It does **not** touch the profile, run consolidation, or change any authorization bit. `observed` evidence and cloud-read defaults are untouched.
33
+ - **Destructive and authorization-changing operations are intentionally NOT exposed as tools.** The following MemoWeft Core methods are **never** registered:
34
+ - `invalidateCognition`, `removeEvidenceSafely`, `removeCognitionSafely`, `mergeCognition`, `archiveCognition`, `resetSubject` — destructive / data loss.
35
+ - `updateEvidenceAuthorization` — changes the cloud-read authorization bit (privacy-sensitive).
36
+ - `handleConversationTurn`, `updateProfile` — run the full ingestion/consolidation pipeline and rewrite the profile.
37
+ - `ingestObservation`, `portable.*` (export/import) — bulk data movement / observation authorization surface.
38
+
39
+ Handing any of these to an autonomous caller carries too much risk. Managing memory (deleting, merging, changing authorization, resetting) stays a human-supervised operation in the host app, not an autonomous tool.
40
+ - **Tool descriptions use neutral protocol wording.** MemoWeft Core is headless — no persona, no anthropomorphized "I remember things about you" copy.
41
+
42
+ ## Install
43
+
44
+ ```sh
45
+ npm install @memoweft/mcp-server
46
+ ```
47
+
48
+ `memoweft` is a peer dependency (`^0.5.0`); install it alongside if it is not already present:
49
+
50
+ ```sh
51
+ npm install memoweft@^0.5.0
52
+ ```
53
+
54
+ ## Run
55
+
56
+ The server talks MCP over stdio. It is normally launched as a subprocess by an MCP client. It requires `MEMOWEFT_DB_PATH` — the path to your MemoWeft database file (there is **no** default path; the server refuses to guess one). Use `:memory:` for an ephemeral database.
57
+
58
+ Example MCP client config (e.g. `claude_desktop_config.json`):
59
+
60
+ ```json
61
+ {
62
+ "mcpServers": {
63
+ "memoweft": {
64
+ "command": "npx",
65
+ "args": ["-y", "@memoweft/mcp-server"],
66
+ "env": {
67
+ "MEMOWEFT_DB_PATH": "/absolute/path/to/memoweft.db"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ Model and embedding configuration follow MemoWeft's standard `.env` loading (see the main package). If they are missing, the server still starts; tools that need a model degrade gracefully (`core.health()` reports readiness) rather than crashing.
75
+
76
+ ## Programmatic use
77
+
78
+ ```ts
79
+ import { createMemoWeftCore } from 'memoweft';
80
+ import { createMcpServer } from '@memoweft/mcp-server';
81
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
82
+
83
+ const core = createMemoWeftCore({ dbPath: process.env.MEMOWEFT_DB_PATH! });
84
+ const server = createMcpServer(core);
85
+ await server.connect(new StdioServerTransport());
86
+ ```
87
+
88
+ ## Registry
89
+
90
+ `server.json` holds the [MCP registry](https://github.com/modelcontextprotocol/registry) metadata. The name `io.github.memoweft/memoweft` is a **placeholder** GitHub namespace. The registry namespace ownership (which GitHub account/org backs `io.github.memoweft/*`) and the actual publish step are done **manually by the maintainer** (this machine has no `gh` installed). Publishing order: publish `memoweft@0.5.0`, then `@memoweft/mcp-server` to npm, then submit to the registry with the `mcp-publisher` CLI. `package.json`'s `mcpName` must stay byte-for-byte equal to `server.json`'s `name`.
91
+
92
+ ## License
93
+
94
+ MIT
@@ -0,0 +1,94 @@
1
+ # @memoweft/mcp-server
2
+
3
+ [English](./README.md) · [简体中文](./README.zh-CN.md)
4
+
5
+ 一个 [MCP](https://modelcontextprotocol.io) 服务器,把 [MemoWeft](https://github.com/memoweft/memoweft) 的记忆库暴露成 Model Context Protocol 工具,让外部 AI 客户端(Claude Desktop、Cursor,或任何支持 MCP 的宿主)能召回已存的知识、记录用户原话。
6
+
7
+ 这是一个**外部集成包**。它包住 MemoWeft 的公开 Core 门面(`createMemoWeftCore`),**不**重新实现任何记忆逻辑,只暴露一个刻意收窄、以只读为主的工具面。
8
+
9
+ ## 工具
10
+
11
+ ### 读(5 个)
12
+
13
+ | 工具 | Core 方法 | 作用 |
14
+ |------|-----------|------|
15
+ | `memoweft_recall` | `core.recall` | 按 query 召回相关认知(带置信度 + 可信状态)。 |
16
+ | `memoweft_list_cognitions` | `core.memory.listCognitions` | 列某 subject 的全部认知,含溯源链与有效置信。 |
17
+ | `memoweft_list_evidence` | `core.memory.listEvidence` | 列某 subject 的全部原始证据(来源)。 |
18
+ | `memoweft_list_events` | `core.memory.listEvents` | 列某 subject 的全部事件,含每条覆盖的证据 id。 |
19
+ | `memoweft_graph` | `core.graph.buildMemoryGraph` | 产出记忆图谱 payload(nodes / edges / stats)。 |
20
+
21
+ ### 写(1 个,轻)
22
+
23
+ | 工具 | Core 方法 | 作用 |
24
+ |------|-----------|------|
25
+ | `memoweft_ingest_user_message` | `core.ingestUserMessage` | 存**一句用户原话**为 spoken 证据。不改画像、不做消化、不授予任何上云授权。 |
26
+
27
+ ## SECURITY —— 这是一个"外部自主调用面"
28
+
29
+ MCP 工具会被**外部 AI 客户端自主调用**,不一定有人逐次审批。这里的工具面就是按这个前提挑的。
30
+
31
+ - **5 个工具只读。** 绝不改动记忆。
32
+ - **1 个工具是轻写**(`memoweft_ingest_user_message`):只把一句用户原话记为 `spoken` 证据。**不**碰画像、不做消化、不改任何授权位。`observed` 证据与"默认不上云"口径不受影响。
33
+ - **破坏性 / 改授权 的操作刻意【不】暴露成工具。** 以下 MemoWeft Core 方法**绝不**注册:
34
+ - `invalidateCognition`、`removeEvidenceSafely`、`removeCognitionSafely`、`mergeCognition`、`archiveCognition`、`resetSubject` —— 破坏性 / 会丢数据。
35
+ - `updateEvidenceAuthorization` —— 改"能否上云"的授权位(隐私敏感)。
36
+ - `handleConversationTurn`、`updateProfile` —— 触发整套摄入 / 消化管线、重写画像。
37
+ - `ingestObservation`、`portable.*`(导出 / 导入)—— 批量数据搬运 / 观察授权面。
38
+
39
+ 把上面任何一个交给自主调用方,风险都过大。管理记忆(删除、合并、改授权、恢复出厂)应留在宿主 App 里由人监督,而不是做成自主工具。
40
+ - **工具描述用中性协议措辞。** MemoWeft Core 无头——没有人设,不写"我回忆起关于你的事"这类拟人文案。
41
+
42
+ ## 安装
43
+
44
+ ```sh
45
+ npm install @memoweft/mcp-server
46
+ ```
47
+
48
+ `memoweft` 是 peer 依赖(`^0.5.0`),若尚未安装请一并装上:
49
+
50
+ ```sh
51
+ npm install memoweft@^0.5.0
52
+ ```
53
+
54
+ ## 运行
55
+
56
+ 服务器经 stdio 讲 MCP,通常由 MCP 客户端拉起为子进程。它需要 `MEMOWEFT_DB_PATH`——你的 MemoWeft 记忆库文件路径(**没有**缺省路径;服务器拒绝擅自猜)。用 `:memory:` 得到一次性内存库。
57
+
58
+ MCP 客户端配置示例(如 `claude_desktop_config.json`):
59
+
60
+ ```json
61
+ {
62
+ "mcpServers": {
63
+ "memoweft": {
64
+ "command": "npx",
65
+ "args": ["-y", "@memoweft/mcp-server"],
66
+ "env": {
67
+ "MEMOWEFT_DB_PATH": "/absolute/path/to/memoweft.db"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ 模型 / 嵌入配置沿用 MemoWeft 的标准 `.env` 加载(见主包)。缺配时服务器照常启动;需要模型的工具走优雅降级(`core.health()` 报能力就绪状态),而不是崩溃。
75
+
76
+ ## 编程方式使用
77
+
78
+ ```ts
79
+ import { createMemoWeftCore } from 'memoweft';
80
+ import { createMcpServer } from '@memoweft/mcp-server';
81
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
82
+
83
+ const core = createMemoWeftCore({ dbPath: process.env.MEMOWEFT_DB_PATH! });
84
+ const server = createMcpServer(core);
85
+ await server.connect(new StdioServerTransport());
86
+ ```
87
+
88
+ ## Registry(注册表)
89
+
90
+ `server.json` 存 [MCP registry](https://github.com/modelcontextprotocol/registry) 元数据。名字 `io.github.memoweft/memoweft` 是**占位**的 GitHub 命名空间。registry 命名空间归属(`io.github.memoweft/*` 背后是哪个 GitHub 账号 / 组织)与实际发布步骤都由**作者手动**完成(本机没装 `gh`)。发布顺序:先发 `memoweft@0.5.0`,再发 `@memoweft/mcp-server` 到 npm,最后用 `mcp-publisher` CLI 提交到 registry。`package.json` 的 `mcpName` 必须与 `server.json` 的 `name` 逐字一致。
91
+
92
+ ## 许可
93
+
94
+ MIT
package/dist/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
package/dist/bin.js ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * MemoWeft MCP server 可执行入口(package.json bin → dist/bin.js 的源)。
4
+ *
5
+ * 从环境变量建 core(缺 MEMOWEFT_DB_PATH 报错退出),起 stdio transport 连接 server。
6
+ * MCP 客户端(Claude Desktop / Cursor / 其它)以子进程方式拉起这个 bin,经 stdin/stdout 通信。
7
+ */
8
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
9
+ import { createCoreFromEnv, createMcpServer } from "./server.js";
10
+ async function main() {
11
+ const core = createCoreFromEnv();
12
+ const server = createMcpServer(core);
13
+ const transport = new StdioServerTransport();
14
+ await server.connect(transport);
15
+ // 连接建立后进程常驻,靠 stdio 收发;stderr 打一行给运维看(stdout 归 JSON-RPC,绝不能污染)。
16
+ process.stderr.write('[memoweft-mcp-server] connected on stdio\n');
17
+ }
18
+ main().catch((err) => {
19
+ process.stderr.write(`[memoweft-mcp-server] fatal: ${err instanceof Error ? err.message : String(err)}\n`);
20
+ process.exit(1);
21
+ });
22
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @memoweft/mcp-server 公开面。
3
+ *
4
+ * 外部集成包:把 MemoWeft Core 门面包成 MCP tool 给外部 AI 客户端自主调用。
5
+ * 只暴露 5 读 + 1 轻写(见 tools.ts 白名单 / README 的 SECURITY 段);
6
+ * 破坏性 / 改上云授权 / 整套消化改画像的 Core 方法一律不注册成 tool。
7
+ */
8
+ export { createMcpServer, createCoreFromEnv, MCP_SERVER_VERSION } from './server.ts';
9
+ export { registerTools, READ_TOOL_NAMES, WRITE_TOOL_NAMES, ALL_TOOL_NAMES, type ToolName, } from './tools.ts';
10
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @memoweft/mcp-server 公开面。
3
+ *
4
+ * 外部集成包:把 MemoWeft Core 门面包成 MCP tool 给外部 AI 客户端自主调用。
5
+ * 只暴露 5 读 + 1 轻写(见 tools.ts 白名单 / README 的 SECURITY 段);
6
+ * 破坏性 / 改上云授权 / 整套消化改画像的 Core 方法一律不注册成 tool。
7
+ */
8
+ export { createMcpServer, createCoreFromEnv, MCP_SERVER_VERSION } from "./server.js";
9
+ export { registerTools, READ_TOOL_NAMES, WRITE_TOOL_NAMES, ALL_TOOL_NAMES, } from "./tools.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * MemoWeft MCP server 装配。
3
+ *
4
+ * 两件事分开:
5
+ * 1. createCoreFromEnv() —— 从环境变量(MEMOWEFT_DB_PATH)建进程内 MemoWeftCore。
6
+ * 缺 MEMOWEFT_DB_PATH 时明确报错要求指定,【不】建危险缺省库(不误写用户其它库/临时库)。
7
+ * 模型 / 嵌入配置沿用 memoweft 的 .env 装配:缺配不崩,真调用才报(见 createMemoWeftCore 文件头)。
8
+ * 2. createMcpServer(core) —— 建 McpServer 并注册白名单 tool,返回配好的 server。
9
+ * 测试可注入一个 :memory: 的假 core,不碰真库真网络。
10
+ */
11
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
12
+ import { type MemoWeftCore } from 'memoweft';
13
+ /** 本包版本(与 package.json 同步;serverInfo 用)。 */
14
+ export declare const MCP_SERVER_VERSION = "0.1.0";
15
+ /**
16
+ * 从环境变量建 core。
17
+ * @throws 若缺 MEMOWEFT_DB_PATH(不建危险缺省库——库路径必须由宿主明确指定)。
18
+ */
19
+ export declare function createCoreFromEnv(): MemoWeftCore;
20
+ /**
21
+ * 建 MCP server 并注册白名单 tool。
22
+ * @param core 进程内 MemoWeftCore 门面(读写都经它)。
23
+ * @returns 配好白名单 tool 的 McpServer(尚未 connect transport)。
24
+ */
25
+ export declare function createMcpServer(core: MemoWeftCore): McpServer;
26
+ //# sourceMappingURL=server.d.ts.map
package/dist/server.js ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * MemoWeft MCP server 装配。
3
+ *
4
+ * 两件事分开:
5
+ * 1. createCoreFromEnv() —— 从环境变量(MEMOWEFT_DB_PATH)建进程内 MemoWeftCore。
6
+ * 缺 MEMOWEFT_DB_PATH 时明确报错要求指定,【不】建危险缺省库(不误写用户其它库/临时库)。
7
+ * 模型 / 嵌入配置沿用 memoweft 的 .env 装配:缺配不崩,真调用才报(见 createMemoWeftCore 文件头)。
8
+ * 2. createMcpServer(core) —— 建 McpServer 并注册白名单 tool,返回配好的 server。
9
+ * 测试可注入一个 :memory: 的假 core,不碰真库真网络。
10
+ */
11
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
12
+ import { createMemoWeftCore } from 'memoweft';
13
+ import { registerTools } from "./tools.js";
14
+ /** 本包版本(与 package.json 同步;serverInfo 用)。 */
15
+ export const MCP_SERVER_VERSION = '0.1.0';
16
+ /**
17
+ * 从环境变量建 core。
18
+ * @throws 若缺 MEMOWEFT_DB_PATH(不建危险缺省库——库路径必须由宿主明确指定)。
19
+ */
20
+ export function createCoreFromEnv() {
21
+ const dbPath = process.env.MEMOWEFT_DB_PATH;
22
+ if (!dbPath || dbPath.trim() === '') {
23
+ throw new Error('MEMOWEFT_DB_PATH is required. Set it to the path of your MemoWeft database file ' +
24
+ "(or ':memory:' for an ephemeral in-memory database). Refusing to guess a default path.");
25
+ }
26
+ // 模型 / 嵌入缺配不崩:createMemoWeftCore 走 loadLLMPool/loadEmbedConfig 降级(真调用才报错)。
27
+ return createMemoWeftCore({ dbPath });
28
+ }
29
+ /**
30
+ * 建 MCP server 并注册白名单 tool。
31
+ * @param core 进程内 MemoWeftCore 门面(读写都经它)。
32
+ * @returns 配好白名单 tool 的 McpServer(尚未 connect transport)。
33
+ */
34
+ export function createMcpServer(core) {
35
+ const server = new McpServer({ name: 'memoweft', version: MCP_SERVER_VERSION }, {
36
+ capabilities: { tools: {} },
37
+ instructions: 'MemoWeft exposes a portable AI memory. Use the read tools (recall, list_*, graph) to ' +
38
+ 'retrieve stored knowledge, and memoweft_ingest_user_message to record a verbatim user ' +
39
+ 'message. Low-credibility cognitions are guesses, not established facts. Destructive and ' +
40
+ 'authorization-changing operations are intentionally not available as tools.',
41
+ });
42
+ // 注册在此单独一层(tools.ts),便于测试枚举核对"没多暴露破坏性面"。
43
+ registerTools(server, core);
44
+ return server;
45
+ }
46
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1,15 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { MemoWeftCore } from 'memoweft';
3
+ /** 白名单 tool 名(snake_case + memoweft_ 前缀)。测试枚举它核对"多一个都不行"。 */
4
+ export declare const READ_TOOL_NAMES: readonly ["memoweft_recall", "memoweft_list_cognitions", "memoweft_list_evidence", "memoweft_list_events", "memoweft_graph"];
5
+ export declare const WRITE_TOOL_NAMES: readonly ["memoweft_ingest_user_message"];
6
+ /** 全部会被注册的 tool 名(读 + 轻写)。测试断言 server 注册的 tool 集合 === 这个集合。 */
7
+ export declare const ALL_TOOL_NAMES: readonly ["memoweft_recall", "memoweft_list_cognitions", "memoweft_list_evidence", "memoweft_list_events", "memoweft_graph", "memoweft_ingest_user_message"];
8
+ export type ToolName = (typeof ALL_TOOL_NAMES)[number];
9
+ /**
10
+ * 把白名单 tool 注册到给定 McpServer。
11
+ * @param server 已建好的 McpServer(serverInfo/capabilities 由 createMcpServer 定)。
12
+ * @param core 进程内的 MemoWeftCore 门面(读写都经它,绝不直接碰 store)。
13
+ */
14
+ export declare function registerTools(server: McpServer, core: MemoWeftCore): void;
15
+ //# sourceMappingURL=tools.d.ts.map
package/dist/tools.js ADDED
@@ -0,0 +1,134 @@
1
+ /**
2
+ * MemoWeft MCP tools —— 白名单注册(外部 AI 客户端自主可调的协议面)。
3
+ *
4
+ * 安全硬约束(见 README 的 SECURITY 段 + 任务书 D3):
5
+ * - 只暴露 6 个 tool:5 读 + 1 轻写(只存一句用户原话)。
6
+ * - 破坏性 / 改上云授权 / 整套消化改画像的 Core 方法【一律不注册】——
7
+ * invalidate、remove、merge、archive、reset、updateEvidenceAuthorization、
8
+ * handleConversationTurn、updateProfile、ingestObservation、portable 都不出现在这里。
9
+ * - tool description 用中性协议措辞,不复活人设(Core 无头)。
10
+ *
11
+ * 这一层只做"把 Core 门面翻译成 MCP tool":取参 → 调门面 → 把结果包成
12
+ * structuredContent + 一段可读 text。缺库/缺模型不崩:读 core.health() 给降级提示。
13
+ */
14
+ import { z } from 'zod';
15
+ /** 白名单 tool 名(snake_case + memoweft_ 前缀)。测试枚举它核对"多一个都不行"。 */
16
+ export const READ_TOOL_NAMES = [
17
+ 'memoweft_recall',
18
+ 'memoweft_list_cognitions',
19
+ 'memoweft_list_evidence',
20
+ 'memoweft_list_events',
21
+ 'memoweft_graph',
22
+ ];
23
+ export const WRITE_TOOL_NAMES = ['memoweft_ingest_user_message'];
24
+ /** 全部会被注册的 tool 名(读 + 轻写)。测试断言 server 注册的 tool 集合 === 这个集合。 */
25
+ export const ALL_TOOL_NAMES = [...READ_TOOL_NAMES, ...WRITE_TOOL_NAMES];
26
+ /** 结果统一包成 { structuredContent, content:[text] }:结构给机器读,text 给人读/兜底。 */
27
+ function ok(payload) {
28
+ return {
29
+ structuredContent: { result: payload },
30
+ content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }],
31
+ };
32
+ }
33
+ /**
34
+ * 把白名单 tool 注册到给定 McpServer。
35
+ * @param server 已建好的 McpServer(serverInfo/capabilities 由 createMcpServer 定)。
36
+ * @param core 进程内的 MemoWeftCore 门面(读写都经它,绝不直接碰 store)。
37
+ */
38
+ export function registerTools(server, core) {
39
+ // ── 读 1:召回相关认知 ───────────────────────────────────────────────
40
+ server.registerTool('memoweft_recall', {
41
+ title: 'Recall memory',
42
+ description: 'Recall stored knowledge relevant to a query. Returns cognitions with confidence and credibility status; low-credibility items are guesses, not established facts.',
43
+ inputSchema: {
44
+ query: z.string().min(1).describe('The query to recall knowledge for.'),
45
+ subjectId: z
46
+ .string()
47
+ .optional()
48
+ .describe('Subject to recall for; defaults to the configured subject.'),
49
+ },
50
+ annotations: { readOnlyHint: true, openWorldHint: false },
51
+ }, async ({ query, subjectId }) => {
52
+ const items = await core.recall({ query, subjectId });
53
+ return ok(items.map((c) => ({
54
+ id: c.id,
55
+ content: c.content,
56
+ confidence: c.confidence,
57
+ credStatus: c.credStatus,
58
+ score: c.score,
59
+ })));
60
+ });
61
+ // ── 读 2:列取认知(画像条目 + 溯源链 + 有效置信)────────────────────
62
+ server.registerTool('memoweft_list_cognitions', {
63
+ title: 'List cognitions',
64
+ description: 'List all stored cognitions for a subject, each with its evidence links and a read-time effective confidence. Read-only.',
65
+ inputSchema: {
66
+ subjectId: z
67
+ .string()
68
+ .optional()
69
+ .describe('Subject to list for; defaults to the configured subject.'),
70
+ },
71
+ annotations: { readOnlyHint: true, openWorldHint: false },
72
+ }, async ({ subjectId }) => ok(core.memory.listCognitions({ subjectId })));
73
+ // ── 读 3:列取证据(原始来源)────────────────────────────────────────
74
+ server.registerTool('memoweft_list_evidence', {
75
+ title: 'List evidence',
76
+ description: 'List all stored evidence (raw sources) for a subject. Read-only; does not expose or change authorization bits.',
77
+ inputSchema: {
78
+ subjectId: z
79
+ .string()
80
+ .optional()
81
+ .describe('Subject to list for; defaults to the configured subject.'),
82
+ },
83
+ annotations: { readOnlyHint: true, openWorldHint: false },
84
+ }, async ({ subjectId }) => ok(core.memory.listEvidence({ subjectId })));
85
+ // ── 读 4:列取事件(证据聚合)───────────────────────────────────────
86
+ server.registerTool('memoweft_list_events', {
87
+ title: 'List events',
88
+ description: 'List all stored events for a subject, each with the ids of the evidence it covers. Read-only.',
89
+ inputSchema: {
90
+ subjectId: z
91
+ .string()
92
+ .optional()
93
+ .describe('Subject to list for; defaults to the configured subject.'),
94
+ },
95
+ annotations: { readOnlyHint: true, openWorldHint: false },
96
+ }, async ({ subjectId }) => ok(core.memory.listEvents({ subjectId })));
97
+ // ── 读 5:记忆图谱 payload(nodes/edges/stats)──────────────────────
98
+ server.registerTool('memoweft_graph', {
99
+ title: 'Build memory graph',
100
+ description: 'Build a memory graph payload (nodes, edges, stats) for a subject. Read-only. Archived cognitions are excluded unless includeArchived is true.',
101
+ inputSchema: {
102
+ subjectId: z
103
+ .string()
104
+ .optional()
105
+ .describe('Subject to build the graph for; defaults to the configured subject.'),
106
+ includeArchived: z
107
+ .boolean()
108
+ .optional()
109
+ .describe('Include archived cognitions in the graph. Defaults to false.'),
110
+ },
111
+ annotations: { readOnlyHint: true, openWorldHint: false },
112
+ }, async ({ subjectId, includeArchived }) => ok(core.graph.buildMemoryGraph({ subjectId, includeArchived })));
113
+ // ── 写·轻:存一句用户原话为 spoken 证据(不改画像、不做消化)──────────
114
+ server.registerTool('memoweft_ingest_user_message', {
115
+ title: 'Ingest user message',
116
+ description: 'Store a single verbatim user message as spoken evidence. This only records the raw message; it does not update the profile, run consolidation, or grant any cloud-read authorization.',
117
+ inputSchema: {
118
+ content: z.string().min(1).describe('The verbatim user message to store.'),
119
+ subjectId: z
120
+ .string()
121
+ .optional()
122
+ .describe('Subject the message belongs to; defaults to the configured subject.'),
123
+ originId: z
124
+ .string()
125
+ .optional()
126
+ .describe('Idempotency key: repeated ingests with the same originId store only once.'),
127
+ },
128
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
129
+ }, async ({ content, subjectId, originId }) => {
130
+ const ev = await core.ingestUserMessage({ content, subjectId, originId });
131
+ return ok({ id: ev.id, subjectId: ev.subjectId, sourceKind: ev.sourceKind, recordedAt: ev.recordedAt });
132
+ });
133
+ }
134
+ //# sourceMappingURL=tools.js.map
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@memoweft/mcp-server",
3
+ "version": "0.1.0",
4
+ "mcpName": "io.github.memoweft/memoweft",
5
+ "description": "MCP server for MemoWeft — expose a portable AI memory (recall, read-only views, and one safe write) as Model Context Protocol tools.",
6
+ "keywords": ["mcp", "model-context-protocol", "memoweft", "memory", "llm", "ai"],
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "bin": { "memoweft-mcp-server": "dist/bin.js" },
12
+ "exports": {
13
+ ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" }
14
+ },
15
+ "files": ["dist/**/*.js", "dist/**/*.d.ts", "README.md", "README.zh-CN.md", "server.json"],
16
+ "engines": { "node": ">=20" },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/memoweft/memoweft.git",
20
+ "directory": "packages/mcp-server"
21
+ },
22
+ "publishConfig": { "access": "public" },
23
+ "scripts": {
24
+ "typecheck": "tsc -p tsconfig.json",
25
+ "test": "node --test \"tests/**/*.test.ts\"",
26
+ "build": "tsc -p tsconfig.build.json",
27
+ "prepublishOnly": "npm run typecheck && npm test && npm run build"
28
+ },
29
+ "dependencies": {
30
+ "@modelcontextprotocol/sdk": "^1.29.0",
31
+ "zod": "^4.0.0"
32
+ },
33
+ "peerDependencies": {
34
+ "memoweft": "^0.5.0"
35
+ },
36
+ "devDependencies": {
37
+ "memoweft": "*"
38
+ }
39
+ }
package/server.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.memoweft/memoweft",
4
+ "description": "Expose a portable AI memory (recall, read-only views, and one safe write) as Model Context Protocol tools. Read-only plus a single verbatim-message write; destructive and authorization-changing operations are intentionally not exposed.",
5
+ "version": "0.1.0",
6
+ "repository": {
7
+ "url": "https://github.com/memoweft/memoweft",
8
+ "source": "github"
9
+ },
10
+ "websiteUrl": "https://github.com/memoweft/memoweft/tree/main/packages/mcp-server",
11
+ "packages": [
12
+ {
13
+ "registryType": "npm",
14
+ "identifier": "@memoweft/mcp-server",
15
+ "version": "0.1.0",
16
+ "transport": { "type": "stdio" },
17
+ "runtimeHint": "npx",
18
+ "environmentVariables": [
19
+ {
20
+ "name": "MEMOWEFT_DB_PATH",
21
+ "description": "Path to the MemoWeft database file (or ':memory:' for an ephemeral in-memory database). Required.",
22
+ "isRequired": true,
23
+ "isSecret": false
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ }