@memoire-ai/mcp-runtime 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.
@@ -0,0 +1,183 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
4
+ import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
5
+ import type { MemoireClient } from '@memoire-ai/sdk';
6
+ import { createMemoireMcpServer } from './index.js';
7
+
8
+ test('handoff MCP tools save, list, and fetch shared handoffs', async () => {
9
+ const calls: Array<{ name: string; args: unknown }> = [];
10
+
11
+ const fakeClient = {
12
+ async assembleContext(args: unknown) {
13
+ calls.push({ name: 'assembleContext', args });
14
+ return {
15
+ context_block: '# Memoire Resume\n\n## Shared Memory\n- Use PKCE for OAuth callbacks',
16
+ sections: [],
17
+ token_count: 120,
18
+ event_ids: ['event-1', 'event-2'],
19
+ active_work: [],
20
+ conflicts: [],
21
+ };
22
+ },
23
+ async createHandoff(args: unknown) {
24
+ calls.push({ name: 'createHandoff', args });
25
+ return {
26
+ handoff: {
27
+ id: 'handoff-1',
28
+ title: 'OAuth callbacks',
29
+ query: 'oauth callbacks',
30
+ summary: 'Use PKCE for OAuth callbacks',
31
+ context_block: '# Memoire Resume\n\n## Shared Memory\n- Use PKCE for OAuth callbacks',
32
+ source_event_ids: ['event-1', 'event-2'],
33
+ created_by_user_id: 'user-1',
34
+ created_at: '2026-03-12T00:00:00.000Z',
35
+ },
36
+ };
37
+ },
38
+ async listHandoffs(args: unknown) {
39
+ calls.push({ name: 'listHandoffs', args });
40
+ return {
41
+ handoffs: [
42
+ {
43
+ id: 'handoff-1',
44
+ title: 'OAuth callbacks',
45
+ query: 'oauth callbacks',
46
+ summary: 'Use PKCE for OAuth callbacks',
47
+ context_block: '# Memoire Resume\n\n## Shared Memory\n- Use PKCE for OAuth callbacks',
48
+ source_event_ids: ['event-1', 'event-2'],
49
+ created_by_user_id: 'user-1',
50
+ created_at: '2026-03-12T00:00:00.000Z',
51
+ },
52
+ ],
53
+ };
54
+ },
55
+ async getHandoff(args: unknown) {
56
+ calls.push({ name: 'getHandoff', args });
57
+ return {
58
+ handoff: {
59
+ id: 'handoff-1',
60
+ title: 'OAuth callbacks',
61
+ query: 'oauth callbacks',
62
+ summary: 'Use PKCE for OAuth callbacks',
63
+ context_block: '# Memoire Resume\n\n## Shared Memory\n- Use PKCE for OAuth callbacks',
64
+ source_event_ids: ['event-1', 'event-2'],
65
+ created_by_user_id: 'user-1',
66
+ created_at: '2026-03-12T00:00:00.000Z',
67
+ },
68
+ };
69
+ },
70
+ } as unknown as MemoireClient;
71
+
72
+ const server = createMemoireMcpServer(
73
+ {
74
+ apiUrl: 'http://localhost:8080',
75
+ apiKey: 'sk_mem_test',
76
+ orgId: 'org-1',
77
+ projectId: 'project-1',
78
+ userId: 'user-1',
79
+ },
80
+ { client: fakeClient }
81
+ );
82
+
83
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
84
+ const mcpClient = new Client({ name: 'memoire-runtime-test', version: '0.1.0' }, { capabilities: {} });
85
+
86
+ await Promise.all([
87
+ server.connect(serverTransport),
88
+ mcpClient.connect(clientTransport),
89
+ ]);
90
+
91
+ try {
92
+ const tools = await mcpClient.listTools();
93
+ const toolNames = tools.tools.map((tool) => tool.name);
94
+
95
+ assert.ok(toolNames.includes('save_handoff'));
96
+ assert.ok(toolNames.includes('list_handoffs'));
97
+ assert.ok(toolNames.includes('get_handoff'));
98
+
99
+ const saved = await mcpClient.callTool({
100
+ name: 'save_handoff',
101
+ arguments: {
102
+ query: 'oauth callbacks',
103
+ title: 'OAuth callbacks',
104
+ token_budget: 900,
105
+ },
106
+ });
107
+
108
+ assert.match(readToolText(saved), /Saved handoff handoff-1/);
109
+ assert.match(readToolText(saved), /Use PKCE for OAuth callbacks/);
110
+
111
+ const listed = await mcpClient.callTool({
112
+ name: 'list_handoffs',
113
+ arguments: { limit: 5 },
114
+ });
115
+
116
+ assert.match(readToolText(listed), /OAuth callbacks/);
117
+ assert.match(readToolText(listed), /handoff-1/);
118
+
119
+ const loaded = await mcpClient.callTool({
120
+ name: 'get_handoff',
121
+ arguments: { handoff_id: 'handoff-1' },
122
+ });
123
+
124
+ assert.match(readToolText(loaded), /^# OAuth callbacks/m);
125
+ assert.match(readToolText(loaded), /Use PKCE for OAuth callbacks/);
126
+
127
+ assert.deepEqual(calls, [
128
+ {
129
+ name: 'assembleContext',
130
+ args: {
131
+ org_id: 'org-1',
132
+ project_id: 'project-1',
133
+ viewer_user_id: 'user-1',
134
+ query: 'oauth callbacks',
135
+ token_budget: 900,
136
+ },
137
+ },
138
+ {
139
+ name: 'createHandoff',
140
+ args: {
141
+ org_id: 'org-1',
142
+ project_id: 'project-1',
143
+ viewer_user_id: 'user-1',
144
+ title: 'OAuth callbacks',
145
+ query: 'oauth callbacks',
146
+ context_block: '# Memoire Resume\n\n## Shared Memory\n- Use PKCE for OAuth callbacks',
147
+ source_event_ids: ['event-1', 'event-2'],
148
+ },
149
+ },
150
+ {
151
+ name: 'listHandoffs',
152
+ args: {
153
+ org_id: 'org-1',
154
+ project_id: 'project-1',
155
+ viewer_user_id: 'user-1',
156
+ limit: 5,
157
+ },
158
+ },
159
+ {
160
+ name: 'getHandoff',
161
+ args: {
162
+ org_id: 'org-1',
163
+ project_id: 'project-1',
164
+ viewer_user_id: 'user-1',
165
+ handoff_id: 'handoff-1',
166
+ },
167
+ },
168
+ ]);
169
+ } finally {
170
+ await Promise.allSettled([mcpClient.close(), server.close()]);
171
+ }
172
+ });
173
+
174
+ function readToolText(result: Awaited<ReturnType<Client['callTool']>>): string {
175
+ if (!('content' in result) || !Array.isArray(result.content)) {
176
+ return '';
177
+ }
178
+
179
+ return result.content
180
+ .filter((item): item is { type: 'text'; text: string } => item.type === 'text')
181
+ .map((item) => item.text)
182
+ .join('\n');
183
+ }