igenius-mcp 0.1.0__tar.gz

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,14 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .env
8
+ .env.*
9
+ !.env.example
10
+ *.log
11
+ .DS_Store
12
+ Thumbs.db
13
+ .venv/
14
+ venv/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 iGenius Memory
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: igenius-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server for iGenius Memory — gives AI agents persistent memory tools via the hosted API
5
+ Project-URL: Homepage, https://igenius-memory.com
6
+ Project-URL: Documentation, https://igenius-memory.info
7
+ Project-URL: Repository, https://github.com/vehoelite/igenius-mcp
8
+ Project-URL: Store, https://igenius-memory.store
9
+ Author-email: iGenius <hello@igenius-memory.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: agent,ai,claude,copilot,igenius,mcp,memory
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: httpx>=0.27.0
23
+ Requires-Dist: mcp>=1.0.0
24
+ Description-Content-Type: text/markdown
25
+
26
+ # iGenius MCP — Thin Memory Server for VS Code
27
+
28
+ A lightweight MCP (Model Context Protocol) server that gives AI agents
29
+ persistent memory via the [iGenius Memory](https://igenius-memory.com) service.
30
+
31
+ No database, no LLM, no local backend required — just an API key.
32
+
33
+ ## Quick Start
34
+
35
+ ```bash
36
+ pip install igenius-mcp
37
+ ```
38
+
39
+ Set your API key and run:
40
+
41
+ ```bash
42
+ export IGENIUS_API_KEY=ig_your_key_here
43
+ igenius-mcp
44
+ ```
45
+
46
+ > **Get a free key** at [igenius-memory.online](https://igenius-memory.online#apikey)
47
+
48
+ ## VS Code Setup
49
+
50
+ Add to `~/.vscode/mcp.json`:
51
+
52
+ ```json
53
+ {
54
+ "servers": {
55
+ "igenius-memory": {
56
+ "command": "igenius-mcp",
57
+ "env": { "IGENIUS_API_KEY": "ig_your_key_here" },
58
+ "type": "stdio"
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ Restart VS Code — all 14 memory tools are now available to Copilot and any
65
+ MCP-compatible agent.
66
+
67
+ ## Available Tools
68
+
69
+ | Tool | Description |
70
+ |------|-------------|
71
+ | `memory_briefing` | Session briefing from all memory layers (call FIRST) |
72
+ | `memory_ingest` | Ingest user/agent messages for AI extraction |
73
+ | `memory_consolidate` | Merge accumulated extracts into master briefing |
74
+ | `memory_process` | Detect trigger words and auto-classify text |
75
+ | `memory_store` | Direct store to a specific memory layer |
76
+ | `memory_search` | Natural language search across memories |
77
+ | `memory_recall` | Retrieve all persistent session memories |
78
+ | `memory_summarize` | LLM-powered summary of a memory layer |
79
+ | `memory_delete` | Delete a memory by ID |
80
+ | `memory_update` | Update fields on an existing memory |
81
+ | `memory_review` | List short-term memories for triage |
82
+ | `memory_promote` | Promote short-term → long-term |
83
+ | `memory_triggers_list` | List trigger words and their layers |
84
+ | `memory_triggers_add` | Add a new trigger word |
85
+
86
+ ## Environment Variables
87
+
88
+ | Variable | Required | Default |
89
+ |----------|----------|---------|
90
+ | `IGENIUS_API_KEY` | Yes | — |
91
+ | `IGENIUS_API_URL` | No | `https://igenius-memory.online/v1` |
92
+
93
+ ## Agent Instructions
94
+
95
+ For best results, add the iGenius agent instructions to your workspace:
96
+
97
+ - **VS Code**: Place `igenius.instructions.md` in `~/.vscode/prompts/`
98
+ - **Claude Code**: Add to `CLAUDE.md`
99
+ - **Workspace**: Add to `.github/copilot-instructions.md`
100
+
101
+ Get the template at [igenius-memory.info](https://igenius-memory.info)
102
+
103
+ ## How It Works
104
+
105
+ ```
106
+ Agent ←→ MCP (stdio) ←→ igenius-mcp ←→ REST API ←→ iGenius Backend
107
+ ```
108
+
109
+ This package is a **thin proxy** — it translates MCP tool calls into REST API
110
+ requests. All processing (AI extraction, LLM summarization, encryption) happens
111
+ server-side. Your data never touches the local machine.
112
+
113
+ ## Plans
114
+
115
+ | Plan | Price | Includes |
116
+ |------|-------|----------|
117
+ | Starter | Free | 50 memories, all 14 tools |
118
+ | Pro | $19/mo | Unlimited memories, priority, encryption |
119
+ | Enterprise | Contact | Custom deployment, SLA |
120
+
121
+ Details at [igenius-memory.store](https://igenius-memory.store)
122
+
123
+ ## Links
124
+
125
+ - [Landing Page](https://igenius-memory.com)
126
+ - [Documentation](https://igenius-memory.info)
127
+ - [API Portal](https://igenius-memory.online)
128
+ - [Store & Plans](https://igenius-memory.store)
129
+
130
+ ## License
131
+
132
+ MIT
@@ -0,0 +1,107 @@
1
+ # iGenius MCP — Thin Memory Server for VS Code
2
+
3
+ A lightweight MCP (Model Context Protocol) server that gives AI agents
4
+ persistent memory via the [iGenius Memory](https://igenius-memory.com) service.
5
+
6
+ No database, no LLM, no local backend required — just an API key.
7
+
8
+ ## Quick Start
9
+
10
+ ```bash
11
+ pip install igenius-mcp
12
+ ```
13
+
14
+ Set your API key and run:
15
+
16
+ ```bash
17
+ export IGENIUS_API_KEY=ig_your_key_here
18
+ igenius-mcp
19
+ ```
20
+
21
+ > **Get a free key** at [igenius-memory.online](https://igenius-memory.online#apikey)
22
+
23
+ ## VS Code Setup
24
+
25
+ Add to `~/.vscode/mcp.json`:
26
+
27
+ ```json
28
+ {
29
+ "servers": {
30
+ "igenius-memory": {
31
+ "command": "igenius-mcp",
32
+ "env": { "IGENIUS_API_KEY": "ig_your_key_here" },
33
+ "type": "stdio"
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ Restart VS Code — all 14 memory tools are now available to Copilot and any
40
+ MCP-compatible agent.
41
+
42
+ ## Available Tools
43
+
44
+ | Tool | Description |
45
+ |------|-------------|
46
+ | `memory_briefing` | Session briefing from all memory layers (call FIRST) |
47
+ | `memory_ingest` | Ingest user/agent messages for AI extraction |
48
+ | `memory_consolidate` | Merge accumulated extracts into master briefing |
49
+ | `memory_process` | Detect trigger words and auto-classify text |
50
+ | `memory_store` | Direct store to a specific memory layer |
51
+ | `memory_search` | Natural language search across memories |
52
+ | `memory_recall` | Retrieve all persistent session memories |
53
+ | `memory_summarize` | LLM-powered summary of a memory layer |
54
+ | `memory_delete` | Delete a memory by ID |
55
+ | `memory_update` | Update fields on an existing memory |
56
+ | `memory_review` | List short-term memories for triage |
57
+ | `memory_promote` | Promote short-term → long-term |
58
+ | `memory_triggers_list` | List trigger words and their layers |
59
+ | `memory_triggers_add` | Add a new trigger word |
60
+
61
+ ## Environment Variables
62
+
63
+ | Variable | Required | Default |
64
+ |----------|----------|---------|
65
+ | `IGENIUS_API_KEY` | Yes | — |
66
+ | `IGENIUS_API_URL` | No | `https://igenius-memory.online/v1` |
67
+
68
+ ## Agent Instructions
69
+
70
+ For best results, add the iGenius agent instructions to your workspace:
71
+
72
+ - **VS Code**: Place `igenius.instructions.md` in `~/.vscode/prompts/`
73
+ - **Claude Code**: Add to `CLAUDE.md`
74
+ - **Workspace**: Add to `.github/copilot-instructions.md`
75
+
76
+ Get the template at [igenius-memory.info](https://igenius-memory.info)
77
+
78
+ ## How It Works
79
+
80
+ ```
81
+ Agent ←→ MCP (stdio) ←→ igenius-mcp ←→ REST API ←→ iGenius Backend
82
+ ```
83
+
84
+ This package is a **thin proxy** — it translates MCP tool calls into REST API
85
+ requests. All processing (AI extraction, LLM summarization, encryption) happens
86
+ server-side. Your data never touches the local machine.
87
+
88
+ ## Plans
89
+
90
+ | Plan | Price | Includes |
91
+ |------|-------|----------|
92
+ | Starter | Free | 50 memories, all 14 tools |
93
+ | Pro | $19/mo | Unlimited memories, priority, encryption |
94
+ | Enterprise | Contact | Custom deployment, SLA |
95
+
96
+ Details at [igenius-memory.store](https://igenius-memory.store)
97
+
98
+ ## Links
99
+
100
+ - [Landing Page](https://igenius-memory.com)
101
+ - [Documentation](https://igenius-memory.info)
102
+ - [API Portal](https://igenius-memory.online)
103
+ - [Store & Plans](https://igenius-memory.store)
104
+
105
+ ## License
106
+
107
+ MIT
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "igenius-mcp"
7
+ version = "0.1.0"
8
+ description = "MCP server for iGenius Memory — gives AI agents persistent memory tools via the hosted API"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "iGenius", email = "hello@igenius-memory.com" }]
13
+ keywords = ["mcp", "ai", "memory", "agent", "copilot", "claude", "igenius"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Topic :: Software Development :: Libraries",
23
+ ]
24
+ dependencies = [
25
+ "mcp>=1.0.0",
26
+ "httpx>=0.27.0",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://igenius-memory.com"
31
+ Documentation = "https://igenius-memory.info"
32
+ Repository = "https://github.com/vehoelite/igenius-mcp"
33
+ Store = "https://igenius-memory.store"
34
+
35
+ [project.scripts]
36
+ igenius-mcp = "igenius_mcp.server:main"
@@ -0,0 +1,10 @@
1
+ # iGenius MCP — Thin API Client for MCP Tools
2
+
3
+ """
4
+ igenius-mcp: A lightweight MCP server that exposes iGenius Memory tools
5
+ by proxying all requests through the hosted REST API.
6
+
7
+ No database, no LLM, no server logic — just a clean MCP ↔ REST bridge.
8
+ """
9
+
10
+ __version__ = "0.1.0"
@@ -0,0 +1,397 @@
1
+ """
2
+ iGenius MCP Server — Thin REST-API proxy.
3
+
4
+ Exposes all 14 iGenius Memory tools as MCP tools by forwarding requests to the
5
+ hosted API at igenius-memory.online. Requires only an API key — no database,
6
+ no LLM, no local backend.
7
+
8
+ Usage:
9
+ pip install igenius-mcp
10
+ IGENIUS_API_KEY=ig_xxx igenius-mcp
11
+
12
+ Or configure in VS Code mcp.json:
13
+ {
14
+ "servers": {
15
+ "igenius-memory": {
16
+ "command": "igenius-mcp",
17
+ "env": { "IGENIUS_API_KEY": "ig_xxx" },
18
+ "type": "stdio"
19
+ }
20
+ }
21
+ }
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import asyncio
27
+ import json
28
+ import os
29
+ import sys
30
+ from typing import Any
31
+
32
+ import httpx
33
+ from mcp.server import Server
34
+ from mcp.server.stdio import stdio_server
35
+ from mcp.types import TextContent, Tool
36
+
37
+ # ─── Configuration ──────────────────────────────────────────────────────────────
38
+
39
+ API_BASE = os.environ.get("IGENIUS_API_URL", "https://igenius-memory.online/v1")
40
+ API_KEY = os.environ.get("IGENIUS_API_KEY", "")
41
+
42
+ if not API_KEY:
43
+ print(
44
+ "ERROR: IGENIUS_API_KEY environment variable is required.\n"
45
+ "Get a free key at https://igenius-memory.online#apikey",
46
+ file=sys.stderr,
47
+ )
48
+
49
+ # ─── HTTP Client ────────────────────────────────────────────────────────────────
50
+
51
+ _client: httpx.AsyncClient | None = None
52
+
53
+
54
+ def _get_client() -> httpx.AsyncClient:
55
+ global _client
56
+ if _client is None or _client.is_closed:
57
+ _client = httpx.AsyncClient(
58
+ base_url=API_BASE,
59
+ headers={
60
+ "X-API-Key": API_KEY,
61
+ "Content-Type": "application/json",
62
+ "User-Agent": "iGenius-MCP/0.1.0",
63
+ },
64
+ timeout=120.0,
65
+ )
66
+ return _client
67
+
68
+
69
+ async def _api(method: str, path: str, body: dict | None = None) -> dict:
70
+ """Make an API request and return JSON response."""
71
+ client = _get_client()
72
+ if method == "GET":
73
+ resp = await client.get(path)
74
+ else:
75
+ resp = await client.post(path, json=body or {})
76
+ resp.raise_for_status()
77
+ return resp.json()
78
+
79
+
80
+ # ─── MCP Server ─────────────────────────────────────────────────────────────────
81
+
82
+ server = Server("igenius-memory")
83
+
84
+ # ─── Tool Definitions ───────────────────────────────────────────────────────────
85
+
86
+ TOOLS: list[Tool] = [
87
+ Tool(
88
+ name="memory_briefing",
89
+ description=(
90
+ "Generate a smart, LLM-synthesised session briefing from ALL memory layers. "
91
+ "Call this FIRST in every new conversation — it replaces the need to "
92
+ "call memory_recall + memory_summarize separately. "
93
+ "Results are cached and only regenerated when underlying memories change."
94
+ ),
95
+ inputSchema={
96
+ "type": "object",
97
+ "properties": {
98
+ "force": {
99
+ "type": "boolean",
100
+ "description": "Force regeneration even if memories haven't changed (default: false).",
101
+ },
102
+ },
103
+ },
104
+ ),
105
+ Tool(
106
+ name="memory_ingest",
107
+ description=(
108
+ "Ingest a single interaction message for AI-powered extraction. "
109
+ "This is the CORE tool — call it for EVERY user prompt, agent response, "
110
+ "tool result, or system message. The AI reads the message, extracts "
111
+ "facts, decisions, credentials, file paths, preferences, and context, "
112
+ "then stores a smart summary as persistent memory."
113
+ ),
114
+ inputSchema={
115
+ "type": "object",
116
+ "properties": {
117
+ "message": {
118
+ "type": "string",
119
+ "description": "The raw interaction message to process.",
120
+ },
121
+ "role": {
122
+ "type": "string",
123
+ "enum": ["user", "agent", "tool", "system"],
124
+ "description": "Who sent this message (default: user).",
125
+ },
126
+ },
127
+ "required": ["message"],
128
+ },
129
+ ),
130
+ Tool(
131
+ name="memory_consolidate",
132
+ description=(
133
+ "Consolidate all accumulated interaction summaries into a master briefing. "
134
+ "Call this before context resets or when context is getting full."
135
+ ),
136
+ inputSchema={
137
+ "type": "object",
138
+ "properties": {
139
+ "force": {
140
+ "type": "boolean",
141
+ "description": "Force regeneration even if nothing new (default: false).",
142
+ },
143
+ },
144
+ },
145
+ ),
146
+ Tool(
147
+ name="memory_process",
148
+ description=(
149
+ "Process raw text through the trigger pipeline. "
150
+ "Detects trigger words, classifies via LLM, and auto-stores to the "
151
+ "appropriate memory layer."
152
+ ),
153
+ inputSchema={
154
+ "type": "object",
155
+ "properties": {
156
+ "text": {
157
+ "type": "string",
158
+ "description": "The raw text to process.",
159
+ },
160
+ },
161
+ "required": ["text"],
162
+ },
163
+ ),
164
+ Tool(
165
+ name="memory_store",
166
+ description=(
167
+ "Directly store a memory into a specific layer, bypassing LLM classification."
168
+ ),
169
+ inputSchema={
170
+ "type": "object",
171
+ "properties": {
172
+ "layer": {
173
+ "type": "string",
174
+ "enum": ["persistent", "long_term", "short_term"],
175
+ },
176
+ "title": {"type": "string", "description": "Short title (max 512 chars)."},
177
+ "content": {"type": "string", "description": "Full memory content."},
178
+ "category": {"type": "string"},
179
+ "importance": {"type": "integer", "minimum": 0, "maximum": 100},
180
+ },
181
+ "required": ["layer", "title", "content"],
182
+ },
183
+ ),
184
+ Tool(
185
+ name="memory_search",
186
+ description=(
187
+ "Search memories by natural language query across short_term and long_term layers."
188
+ ),
189
+ inputSchema={
190
+ "type": "object",
191
+ "properties": {
192
+ "query": {"type": "string", "description": "Search query."},
193
+ "limit": {"type": "integer", "minimum": 1, "maximum": 100},
194
+ },
195
+ "required": ["query"],
196
+ },
197
+ ),
198
+ Tool(
199
+ name="memory_recall",
200
+ description=(
201
+ "Retrieve all active persistent memories (interaction extracts from current session)."
202
+ ),
203
+ inputSchema={"type": "object", "properties": {}},
204
+ ),
205
+ Tool(
206
+ name="memory_summarize",
207
+ description=(
208
+ "Summarize memories in a layer using the LLM."
209
+ ),
210
+ inputSchema={
211
+ "type": "object",
212
+ "properties": {
213
+ "layer": {
214
+ "type": "string",
215
+ "enum": ["persistent", "long_term", "short_term"],
216
+ },
217
+ "limit": {"type": "integer", "minimum": 1, "maximum": 200},
218
+ },
219
+ },
220
+ ),
221
+ Tool(
222
+ name="memory_delete",
223
+ description="Delete a memory by its ID.",
224
+ inputSchema={
225
+ "type": "object",
226
+ "properties": {
227
+ "memory_id": {"type": "integer", "description": "The memory ID to delete."},
228
+ },
229
+ "required": ["memory_id"],
230
+ },
231
+ ),
232
+ Tool(
233
+ name="memory_update",
234
+ description="Update fields on an existing memory.",
235
+ inputSchema={
236
+ "type": "object",
237
+ "properties": {
238
+ "memory_id": {"type": "integer"},
239
+ "title": {"type": "string"},
240
+ "content": {"type": "string"},
241
+ "category": {"type": "string"},
242
+ "importance": {"type": "integer", "minimum": 0, "maximum": 100},
243
+ "layer": {"type": "string", "enum": ["persistent", "long_term", "short_term"]},
244
+ },
245
+ "required": ["memory_id"],
246
+ },
247
+ ),
248
+ Tool(
249
+ name="memory_review",
250
+ description=(
251
+ "List short-term memories for user triage. Promote keepers or discard."
252
+ ),
253
+ inputSchema={
254
+ "type": "object",
255
+ "properties": {
256
+ "limit": {"type": "integer", "minimum": 1, "maximum": 200},
257
+ },
258
+ },
259
+ ),
260
+ Tool(
261
+ name="memory_promote",
262
+ description="Promote a short-term memory to long-term storage.",
263
+ inputSchema={
264
+ "type": "object",
265
+ "properties": {
266
+ "memory_id": {"type": "integer"},
267
+ },
268
+ "required": ["memory_id"],
269
+ },
270
+ ),
271
+ Tool(
272
+ name="memory_triggers_list",
273
+ description="List all configured trigger words and their target layers.",
274
+ inputSchema={"type": "object", "properties": {}},
275
+ ),
276
+ Tool(
277
+ name="memory_triggers_add",
278
+ description="Add a new trigger word that maps to a memory layer.",
279
+ inputSchema={
280
+ "type": "object",
281
+ "properties": {
282
+ "word": {"type": "string"},
283
+ "target_layer": {"type": "string", "enum": ["persistent", "long_term", "short_term"]},
284
+ "description": {"type": "string"},
285
+ },
286
+ "required": ["word", "target_layer"],
287
+ },
288
+ ),
289
+ ]
290
+
291
+
292
+ # ─── Tool Dispatch ──────────────────────────────────────────────────────────────
293
+
294
+ ROUTE_MAP: dict[str, tuple[str, str]] = {
295
+ # name → (HTTP method, path template)
296
+ "memory_briefing": ("GET", "/briefing"),
297
+ "memory_ingest": ("POST", "/ingest"),
298
+ "memory_consolidate": ("POST", "/consolidate"),
299
+ "memory_process": ("POST", "/process"),
300
+ "memory_store": ("POST", "/memories"),
301
+ "memory_search": ("GET", "/memories/search"),
302
+ "memory_recall": ("GET", "/memories/layer/persistent"),
303
+ "memory_summarize": ("POST", "/memories/summarize"),
304
+ "memory_delete": ("DELETE", "/memories/{memory_id}"),
305
+ "memory_update": ("PATCH", "/memories/{memory_id}"),
306
+ "memory_review": ("GET", "/memories/review"),
307
+ "memory_promote": ("POST", "/memories/{memory_id}/promote"),
308
+ "memory_triggers_list": ("GET", "/triggers"),
309
+ "memory_triggers_add": ("POST", "/triggers"),
310
+ }
311
+
312
+
313
+ @server.list_tools()
314
+ async def list_tools() -> list[Tool]:
315
+ return TOOLS
316
+
317
+
318
+ @server.call_tool()
319
+ async def call_tool(name: str, arguments: dict[str, Any]) -> list[TextContent]:
320
+ try:
321
+ result = await _dispatch(name, arguments)
322
+ return [TextContent(type="text", text=json.dumps(result, indent=2, default=str))]
323
+ except httpx.HTTPStatusError as e:
324
+ detail = e.response.text
325
+ try:
326
+ detail = e.response.json().get("detail", detail)
327
+ except Exception:
328
+ pass
329
+ return [TextContent(type="text", text=json.dumps({"error": str(detail), "status": e.response.status_code}))]
330
+ except Exception as e:
331
+ return [TextContent(type="text", text=json.dumps({"error": str(e)}))]
332
+
333
+
334
+ async def _dispatch(name: str, args: dict[str, Any]) -> Any:
335
+ """Route tool calls to REST API endpoints."""
336
+ route = ROUTE_MAP.get(name)
337
+ if not route:
338
+ return {"error": f"Unknown tool: {name}"}
339
+
340
+ method, path_template = route
341
+ client = _get_client()
342
+
343
+ # Substitute path params like {memory_id}
344
+ path = path_template
345
+ path_args = {}
346
+ for key in list(args.keys()):
347
+ placeholder = f"{{{key}}}"
348
+ if placeholder in path_template:
349
+ path = path.replace(placeholder, str(args[key]))
350
+ path_args[key] = args.pop(key)
351
+
352
+ # Build request
353
+ if method == "GET":
354
+ # Convert remaining args to query params
355
+ params = {}
356
+ if name == "memory_briefing" and args.get("force"):
357
+ params["force"] = "true"
358
+ elif name == "memory_search":
359
+ params["q"] = args.get("query", "")
360
+ if args.get("limit"):
361
+ params["limit"] = str(args["limit"])
362
+ elif name == "memory_review":
363
+ if args.get("limit"):
364
+ params["limit"] = str(args["limit"])
365
+ resp = await client.get(path, params=params)
366
+ elif method == "DELETE":
367
+ resp = await client.delete(path)
368
+ elif method == "PATCH":
369
+ resp = await client.patch(path, json=args)
370
+ else:
371
+ resp = await client.post(path, json=args)
372
+
373
+ resp.raise_for_status()
374
+ return resp.json()
375
+
376
+
377
+ # ─── Entry point ────────────────────────────────────────────────────────────────
378
+
379
+ async def _run():
380
+ if not API_KEY:
381
+ print(
382
+ "FATAL: Set IGENIUS_API_KEY environment variable.\n"
383
+ "Get a free key at https://igenius-memory.online#apikey",
384
+ file=sys.stderr,
385
+ )
386
+ sys.exit(1)
387
+
388
+ async with stdio_server() as (read_stream, write_stream):
389
+ await server.run(read_stream, write_stream, server.create_initialization_options())
390
+
391
+
392
+ def main():
393
+ asyncio.run(_run())
394
+
395
+
396
+ if __name__ == "__main__":
397
+ main()