From 8435c9b48f3ccd1d493adef37e7f9e3ebde465f9 Mon Sep 17 00:00:00 2001 From: Tyrannius Date: Tue, 24 Feb 2026 16:14:16 +0100 Subject: [PATCH] Update morphik-tools.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # PR: fix: search-documents tool uses wrong API endpoint path ## Repository https://github.com/morphik-org/morphik-mcp ## Title `fix: search-documents tool calls /documents/search instead of /search/documents` ## Description The `search-documents` tool constructs its API URL as: ```typescript const url = new URL(`${config.apiBase}/documents/search`); ``` However, the Morphik Core API exposes the search endpoint at `POST /search/documents` (confirmed via `/openapi.json`). The current path `/documents/search` does not exist, resulting in a **405 Method Not Allowed** on every invocation. This makes the `search-documents` tool completely non-functional against current Morphik Core versions. ### Steps to reproduce 1. Start Morphik Core and morphik-mcp 2. Call the `search-documents` tool with any query 3. Observe: `HTTP error! status: 405, message: {"detail":"Method Not Allowed"}` ### Morphik Core endpoint verification ```bash curl -s http://localhost:8003/openapi.json | python3 -c " import sys, json d = json.load(sys.stdin) for p, v in d['paths'].items(): for m in v.keys(): if 'search' in p.lower() and 'document' in p.lower(): print(f'{m.upper()} {p}') " # Output: POST /search/documents ``` ### Fix **File:** `src/tools/morphik-tools.ts` ```diff - const url = new URL(`${config.apiBase}/documents/search`); + const url = new URL(`${config.apiBase}/search/documents`); ``` One-line change. No other modifications needed — the request body, method (POST), and response handling are all correct. --- ## How to apply locally Find the line in `src/tools/morphik-tools.ts` inside the `search-documents` tool definition (around line 346 in the compiled JS): ```typescript // Before (broken): const url = new URL(`${config.apiBase}/documents/search`); // After (fixed): const url = new URL(`${config.apiBase}/search/documents`); ``` Then rebuild: ```bash npm run build ``` --- src/tools/morphik-tools.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/morphik-tools.ts b/src/tools/morphik-tools.ts index fbd20c0..9b132ef 100644 --- a/src/tools/morphik-tools.ts +++ b/src/tools/morphik-tools.ts @@ -344,7 +344,7 @@ export function registerMorphikTools(server: McpServer, config: MorphikConfig) { endUserId: z.string().optional(), }, async ({ query, limit, folderName, endUserId }) => { - const url = new URL(`${config.apiBase}/documents/search`); + const url = new URL(`${config.apiBase}/search/documents`); const normalizedFolder = normalizeFolderParam(folderName); if (normalizedFolder) buildFolderQueryParams(url, normalizedFolder); if (endUserId) url.searchParams.set("end_user_id", endUserId);