Skip to content

Commit 3bef4a2

Browse files
fix: Add project parameter to ChatGPT MCP tools
- Updated search() and fetch() tools to accept project parameter - Pass project parameter to underlying search_notes and read_note functions - Updated all integration tests to provide project parameter - Fixes test failures due to missing project specification Co-authored-by: Drew Cain <groksrc@users.noreply.github.com>
1 parent 656f5fb commit 3bef4a2

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/basic_memory/mcp/tools/chatgpt_tools.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,27 @@ def _format_document_for_chatgpt(
7777
)
7878
async def search(
7979
query: str,
80+
project: Optional[str] = None,
8081
context: Context | None = None,
8182
) -> List[Dict[str, Any]]:
8283
"""ChatGPT/OpenAI MCP search adapter returning a single text content item.
8384
8485
Args:
8586
query: Search query (full-text syntax supported by `search_notes`)
87+
project: Optional project name for multi-project support
8688
context: Optional FastMCP context passed through for auth/session data
8789
8890
Returns:
8991
List with one dict: `{ "type": "text", "text": "{...JSON...}" }`
9092
where the JSON body contains `results`, `total_count`, and echo of `query`.
9193
"""
92-
logger.info(f"ChatGPT search request: query='{query}'")
94+
logger.info(f"ChatGPT search request: query='{query}', project='{project}'")
9395

9496
try:
9597
# Call underlying search_notes with sensible defaults for ChatGPT
9698
results = await search_notes.fn(
9799
query=query,
100+
project=project,
98101
page=1,
99102
page_size=10, # Reasonable default for ChatGPT consumption
100103
search_type="text", # Default to full-text search
@@ -147,24 +150,27 @@ async def search(
147150
)
148151
async def fetch(
149152
id: str,
153+
project: Optional[str] = None,
150154
context: Context | None = None,
151155
) -> List[Dict[str, Any]]:
152156
"""ChatGPT/OpenAI MCP fetch adapter returning a single text content item.
153157
154158
Args:
155159
id: Document identifier (permalink, title, or memory URL)
160+
project: Optional project name for multi-project support
156161
context: Optional FastMCP context passed through for auth/session data
157162
158163
Returns:
159164
List with one dict: `{ "type": "text", "text": "{...JSON...}" }`
160165
where the JSON body includes `id`, `title`, `text`, `url`, and metadata.
161166
"""
162-
logger.info(f"ChatGPT fetch request: id='{id}'")
167+
logger.info(f"ChatGPT fetch request: id='{id}', project='{project}'")
163168

164169
try:
165170
# Call underlying read_note function
166171
content = await read_note.fn(
167172
identifier=id,
173+
project=project,
168174
page=1,
169175
page_size=10, # Default pagination
170176
context=context

test-int/mcp/test_chatgpt_tools_integration.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ async def test_chatgpt_search_basic(mcp_server, app, test_project):
6464
"search",
6565
{
6666
"query": "Machine Learning",
67+
"project": test_project.name,
6768
},
6869
)
6970

@@ -99,6 +100,7 @@ async def test_chatgpt_search_empty_results(mcp_server, app, test_project):
99100
"search",
100101
{
101102
"query": "NonExistentTopic12345",
103+
"project": test_project.name,
102104
},
103105
)
104106

@@ -150,6 +152,7 @@ async def test_chatgpt_search_with_boolean_operators(mcp_server, app, test_proje
150152
"search",
151153
{
152154
"query": "Python AND frameworks",
155+
"project": test_project.name,
153156
},
154157
)
155158

@@ -201,6 +204,7 @@ def wrapper(*args, **kwargs):
201204
"fetch",
202205
{
203206
"id": "Advanced Python Techniques",
207+
"project": test_project.name,
204208
},
205209
)
206210

@@ -246,6 +250,7 @@ async def test_chatgpt_fetch_by_permalink(mcp_server, app, test_project):
246250
"search",
247251
{
248252
"query": "Test Document",
253+
"project": test_project.name,
249254
},
250255
)
251256

@@ -258,6 +263,7 @@ async def test_chatgpt_fetch_by_permalink(mcp_server, app, test_project):
258263
"fetch",
259264
{
260265
"id": permalink,
266+
"project": test_project.name,
261267
},
262268
)
263269

@@ -278,6 +284,7 @@ async def test_chatgpt_fetch_nonexistent_document(mcp_server, app, test_project)
278284
"fetch",
279285
{
280286
"id": "NonExistentDocument12345",
287+
"project": test_project.name,
281288
},
282289
)
283290

@@ -321,6 +328,7 @@ async def test_chatgpt_fetch_with_empty_title(mcp_server, app, test_project):
321328
"fetch",
322329
{
323330
"id": "untitled-note",
331+
"project": test_project.name,
324332
},
325333
)
326334

@@ -357,6 +365,7 @@ async def test_chatgpt_search_pagination_default(mcp_server, app, test_project):
357365
"search",
358366
{
359367
"query": "Test Note",
368+
"project": test_project.name,
360369
},
361370
)
362371

@@ -378,6 +387,7 @@ async def test_chatgpt_tools_error_handling(mcp_server, app, test_project):
378387
"search",
379388
{
380389
"query": "", # Empty query might cause an error
390+
"project": test_project.name,
381391
},
382392
)
383393

@@ -438,6 +448,7 @@ async def test_chatgpt_integration_workflow(mcp_server, app, test_project):
438448
"search",
439449
{
440450
"query": "API",
451+
"project": test_project.name,
441452
},
442453
)
443454

@@ -450,6 +461,7 @@ async def test_chatgpt_integration_workflow(mcp_server, app, test_project):
450461
"fetch",
451462
{
452463
"id": first_result_id,
464+
"project": test_project.name,
453465
},
454466
)
455467

0 commit comments

Comments
 (0)