Skip to content

mcp / tools update + internal tool#1283

Open
mantrakp04 wants to merge 6 commits intodevfrom
dario-likes-mcps
Open

mcp / tools update + internal tool#1283
mantrakp04 wants to merge 6 commits intodevfrom
dario-likes-mcps

Conversation

@mantrakp04
Copy link
Copy Markdown
Collaborator

@mantrakp04 mantrakp04 commented Mar 23, 2026

  • Added new internal API endpoint for documentation tools, allowing actions such as listing available docs, searching, and fetching specific documentation by ID.
  • Updated environment configuration to support optional internal secret for enhanced security.
  • Refactored existing search functionality to utilize the new docs tools API instead of the previous MCP server.
  • Improved error handling and response parsing for documentation-related requests.
  • Expanded documentation to clarify the relationship between the new tools and existing API functionalities.

This update streamlines the documentation access process and enhances the overall developer experience.

Summary by CodeRabbit

  • New Features

    • Non-stream AI responses now include a consolidated finalText for clearer answers.
    • New internal docs-tools API to power doc listing, search, and fetch with optional header-based access control and configurable service origin.
  • Refinement

    • Multiple doc tooling paths consolidated into a single question-focused flow; backend now calls the unified docs-tools endpoint.
  • Documentation

    • Guides and knowledge docs updated to describe the new docs query flow and optional env configuration.

- Added new internal API endpoint for documentation tools, allowing actions such as listing available docs, searching, and fetching specific documentation by ID.
- Updated environment configuration to support optional internal secret for enhanced security.
- Refactored existing search functionality to utilize the new docs tools API instead of the previous MCP server.
- Improved error handling and response parsing for documentation-related requests.
- Expanded documentation to clarify the relationship between the new tools and existing API functionalities.

This update streamlines the documentation access process and enhances the overall developer experience.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment Mar 25, 2026 10:54pm
stack-backend Ready Ready Preview, Comment Mar 25, 2026 10:54pm
stack-dashboard Ready Ready Preview, Comment Mar 25, 2026 10:54pm
stack-demo Ready Ready Preview, Comment Mar 25, 2026 10:54pm
stack-docs Ready Ready Preview, Comment Mar 25, 2026 10:54pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f89491d-1ad0-4e59-b9ef-ef0abe1e01a8

📥 Commits

Reviewing files that changed from the base of the PR and between aaf49db and 844e916.

📒 Files selected for processing (1)
  • docs/src/app/api/internal/[transport]/route.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/src/app/api/internal/[transport]/route.ts

📝 Walkthrough

Walkthrough

Refactors docs tooling to use a new HTTP-backed internal endpoint (/api/internal/docs-tools) with optional secret gating; moves tool implementations into docs-side operations; backend and docs callers now POST typed action payloads and consume JSON results; non-stream AI responses include finalText.

Changes

Cohort / File(s) Summary
Backend HTTP-backed Docs Tools
apps/backend/src/lib/ai/tools/docs.ts
Replace MCP client with HTTP tool wrappers that POST action payloads to docs /api/internal/docs-tools; derive base URL from env and attach optional internal secret header.
Backend AI Query Response
apps/backend/src/app/api/latest/ai/query/[mode]/route.ts
Non-stream response extended to include finalText (from result.text) alongside existing content.
Backend Dev Env
apps/backend/.env.development
Added commented env docs for STACK_DOCS_INTERNAL_BASE_URL and STACK_INTERNAL_DOCS_TOOLS_SECRET (comments only).
Docs: Internal Endpoint
docs/src/app/api/internal/docs-tools/route.ts
New POST /api/internal/docs-tools (and GET -> 405) with optional x-stack-internal-docs-tools-secret validation, JSON parsing, zod-discriminated action validation, and dispatch to executeDocsToolAction.
Docs: Tool Implementations
docs/src/lib/docs-tools-operations.ts
New module implementing DocsToolAction + executeDocsToolAction: list/search/get_by_id/fetch/setup-instructions over precomputed pages, file reads, OpenAPI parsing, scoring, and CallToolResult shaping; optional PostHog events.
Docs: MCP Handler Simplified
docs/src/app/api/internal/[transport]/route.ts
Removed many MCP in-process docs tools and replaced with single ask_stack_auth tool that forwards questions to backend AI endpoint; increased MCP maxDuration to 120s.
Docs Consumers
docs/src/app/api/search/route.ts, docs/src/app/mcp-browser/page.tsx
Switched callers from JSON-RPC/SSE MCP protocol to POSTing action payloads to /api/internal/docs-tools; removed SSE parsing and updated payload/response shapes and logs.
Docs Content & Env Docs
docs/content/docs/(guides)/others/mcp-setup.mdx, docs/src/app/api/internal/[transport]/setup-instructions.md, claude/CLAUDE-KNOWLEDGE.md, docs/.env.development
Docs updated to describe ask_stack_auth, new docs-tools endpoint, optional secret and base URL override, and revised setup wording.

Sequence Diagram

sequenceDiagram
    participant BackendAI as Backend AI Tools
    participant BackendHTTP as Backend HTTP Client
    participant DocsAPI as Docs /api/internal/docs-tools
    participant DocsOps as DocsToolsOperations
    participant Content as Docs Content Files

    BackendAI->>BackendHTTP: POST action (e.g. search_docs)
    BackendHTTP->>DocsAPI: POST /api/internal/docs-tools (body + optional x-stack-internal-docs-tools-secret)
    DocsAPI->>DocsAPI: validate secret (if configured)
    DocsAPI->>DocsOps: executeDocsToolAction(action)
    DocsOps->>Content: read pages, files, OpenAPI specs
    DocsOps-->>DocsAPI: return CallToolResult (content array / isError)
    DocsAPI-->>BackendHTTP: JSON response
    BackendHTTP-->>BackendAI: parsed content (and finalText for non-stream)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • madster456
  • N2D4

Poem

🐰 I hopped from streams to HTTP bright,

Posting actions through the night,
A secret header snug and tight,
Pages read, answers stitched in light,
The rabbit cheers — docs-tools take flight.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'mcp / tools update + internal tool' is vague and uses generic terms ('update', 'tool') without clearly conveying the primary change—a refactoring from MCP-based documentation tools to a new internal API endpoint. Consider a more specific title such as 'Refactor docs tools from MCP to internal API endpoint' or 'Replace MCP server with internal docs-tools API' to better clarify the main architectural change.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description covers the key aspects of the change—new internal endpoint, environment configuration, refactored search, error handling, and documentation updates—aligning well with the changeset's objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dario-likes-mcps

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 23, 2026

Greptile Summary

This PR refactors the Stack Auth documentation tooling layer by replacing the previous MCP-over-SSE approach (with complex JSON-RPC/SSE parsing) with a simple internal JSON HTTP API (POST /api/internal/docs-tools). The backend's createDocsTools() now calls this endpoint directly instead of connecting to the docs MCP server, breaking the previous MCP recursion risk. The public MCP surface is simultaneously simplified to a single ask_stack_auth tool that proxies to the backend AI endpoint.

Key changes:

  • New docs/src/lib/docs-tools-operations.ts: Centralises all doc-lookup logic (listing pages, searching, fetching by ID, reading setup instructions) previously scattered across the MCP route handler (~500 lines removed from that file).
  • New docs/src/app/api/internal/docs-tools/route.ts: Internal HTTP endpoint wrapping the operations library; optional shared-secret gate via STACK_INTERNAL_DOCS_TOOLS_SECRET.
  • apps/backend/src/lib/ai/tools/docs.ts: Replaces createMCPClient with direct fetch calls to the docs-tools endpoint; registers 6 typed AI SDK tools.
  • apps/backend/src/app/api/latest/ai/query/[mode]/route.ts: Adds finalText to the response, enabling the MCP handler to surface the final assistant text without scanning content blocks.
  • docs/src/app/api/search/route.ts and mcp-browser/page.tsx: Both updated to call the new internal JSON API instead of the MCP server, removing ~70 lines of SSE stream-parsing boilerplate each.
  • Three P2 style suggestions: use new Headers() instead of a plain object with dynamic keys in docs.ts, add path sanitisation for the spec file read in docs-tools-operations.ts (pre-existing gap), and add the Allow: POST header to the 405 GET response in the new route.

Confidence Score: 4/5

  • Safe to merge after addressing the minor style suggestions; no regressions or security issues introduced.
  • The refactor is architecturally clean and removes significant complexity (SSE parsing, MCP recursion risk, duplicated search logic). All three issues flagged are non-blocking P2 style/best-practice suggestions. The only pre-existing risk (unsanitised spec file path) is not worsened by this PR.
  • docs/src/lib/docs-tools-operations.ts (path sanitisation for OpenAPI spec reads) and apps/backend/src/lib/ai/tools/docs.ts (Headers object style)

Important Files Changed

Filename Overview
apps/backend/src/lib/ai/tools/docs.ts Replaces MCP client with direct HTTP calls to docs /api/internal/docs-tools; introduces 6 typed tool wrappers. Minor: headers uses a plain object with a dynamic key instead of new Headers().
docs/src/lib/docs-tools-operations.ts New shared library that centralises all doc-tool logic (previously in the MCP route handler). Path traversal gap exists for the OpenAPI spec file read, though it is a pre-existing issue moved from the old route handler.
docs/src/app/api/internal/docs-tools/route.ts New internal JSON API endpoint wrapping executeDocsToolAction. Secret validation, Zod schema, and error handling all look correct. Minor: GET 405 is missing the required Allow header.
docs/src/app/api/internal/[transport]/route.ts MCP handler drastically simplified to a single ask_stack_auth tool that proxies to the backend AI endpoint, eliminating ~500 lines of in-process doc search logic. Uses finalText from the new backend response field.
docs/src/app/api/search/route.ts Switches from JSON-RPC/SSE MCP call to a simple POST to the internal docs-tools endpoint on the same origin. SSE stream-parsing boilerplate removed; response shape is now straightforward JSON.
apps/backend/src/app/api/latest/ai/query/[mode]/route.ts Adds finalText: result.text to the response body, enabling the MCP handler to display the final assistant message without scanning content blocks.

Sequence Diagram

sequenceDiagram
    participant MCP as MCP Client (Cursor/IDE)
    participant DocsMCP as Docs MCP Server<br/>/api/internal/[transport]
    participant Backend as Backend API<br/>/api/latest/ai/query/generate
    participant DocsTools as Docs Tools API<br/>/api/internal/docs-tools
    participant Ops as docs-tools-operations.ts<br/>(file system / page index)

    MCP->>DocsMCP: ask_stack_auth { question, reason }
    DocsMCP->>Backend: POST /api/latest/ai/query/generate<br/>{ tools: ["docs"], messages: [{question}] }
    Backend->>DocsTools: POST /api/internal/docs-tools<br/>{ action: "search_docs" | "get_docs_by_id" | … }
    DocsTools->>Ops: executeDocsToolAction(action)
    Ops-->>DocsTools: CallToolResult { content }
    DocsTools-->>Backend: JSON { content, isError? }
    Backend-->>DocsMCP: { finalText, content[] }
    DocsMCP-->>MCP: text response

    Note over DocsTools,Ops: Also called directly by<br/>/api/search and mcp-browser
Loading

Fix All in Claude Code Fix All in Cursor Fix All in Codex

Reviews (1): Last reviewed commit: "Merge branch 'dev' into dario-likes-mcps" | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Stack Auth documentation tooling by introducing a typed internal docs-tools HTTP endpoint on the docs app, migrating backend “docs” AI tools to use it directly (instead of MCP), and simplifying the public MCP surface to a single ask_stack_auth tool that proxies to the backend AI query endpoint.

Changes:

  • Added POST /api/internal/docs-tools (typed actions) and moved docs list/search/fetch logic into a shared server module.
  • Updated docs UI + docs search API to call the new internal docs-tools endpoint (JSON instead of SSE/JSON-RPC).
  • Simplified the public MCP endpoint to only expose ask_stack_auth and added optional shared-secret gating for docs-tools calls.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
docs/src/lib/docs-tools-operations.ts New shared implementation for list/search/fetch + OpenAPI extraction used by the internal docs-tools route.
docs/src/app/mcp-browser/page.tsx Switches MCP-browser UI from MCP JSON-RPC/SSE parsing to internal docs-tools JSON API.
docs/src/app/api/search/route.ts Refactors docs-site search endpoint to use internal docs-tools search action.
docs/src/app/api/internal/docs-tools/route.ts New internal HTTP API endpoint exposing typed docs tool actions, with optional secret header check.
docs/src/app/api/internal/[transport]/setup-instructions.md Updates wording to reflect ask_stack_auth being the MCP tool.
docs/src/app/api/internal/[transport]/route.ts Replaces multiple MCP tools with a single ask_stack_auth tool that calls backend AI query/generate.
docs/content/docs/(guides)/others/mcp-setup.mdx Documents the new MCP surface (ask_stack_auth) and updated feature set.
docs/.env.development Adds optional STACK_INTERNAL_DOCS_TOOLS_SECRET guidance for docs-tools route.
claude/CLAUDE-KNOWLEDGE.md Updates internal knowledge notes describing new MCP/docs-tools architecture.
apps/backend/src/lib/ai/tools/docs.ts Replaces MCP client usage with direct HTTP calls to docs app /api/internal/docs-tools.
apps/backend/src/app/api/latest/ai/query/[mode]/route.ts Adds finalText to the JSON response payload (alongside content).
apps/backend/.env.development Documents new env vars for docs-tools base URL override + optional shared secret.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Nitpick comments (2)
docs/src/app/api/internal/[transport]/route.ts (1)

59-70: Unsafe type assertion on backend response.

The as { finalText?, content? } cast bypasses type safety. If the backend response shape changes or returns an error object, this will fail silently. Per coding guidelines, prefer runtime validation or defensive checks.

♻️ Proposed fix to add defensive validation
-        const body = (await res.json()) as {
-          finalText?: string,
-          content?: Array<{ type: string, text?: string }>,
-        };
-
-        const text =
-          body.finalText ??
-          body.content
-            ?.filter((c): c is { type: "text", text: string } => c.type === "text" && typeof c.text === "string")
-            .map((c) => c.text)
-            .join("\n\n") ??
-          "";
+        const body = await res.json();
+        
+        // Defensive validation of response shape
+        const finalText = typeof body?.finalText === "string" ? body.finalText : undefined;
+        const contentArray = Array.isArray(body?.content) ? body.content : [];
+        
+        const text =
+          finalText ??
+          contentArray
+            .filter((c): c is { type: "text", text: string } => 
+              c != null && c.type === "text" && typeof c.text === "string")
+            .map((c) => c.text)
+            .join("\n\n") ??
+          "";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/src/app/api/internal/`[transport]/route.ts around lines 59 - 70, The
code unsafely casts the fetch response to a specific shape using "as {
finalText?, content? }" when computing the "body" and "text" variables in
route.ts; replace this with runtime validation: after awaiting res.json(), check
res.ok and that the parsed value is an object, then validate that body.finalText
(if present) is a string or that body.content is an array whose items have type
=== "text" and text is a string before using them to build "text"; if validation
fails, handle the error path (log or throw) and fall back to "" (or a safe
default). If your codebase uses a runtime schema validator (e.g., zod), validate
the response against a schema instead of the assertion; update all uses of
"body" and the "text" assembly accordingly.
docs/src/app/mcp-browser/page.tsx (1)

50-50: Unsafe type assertion on API response.

The as { content: ... } cast bypasses type safety. Per coding guidelines, type casts should be avoided. If the response shape is unexpected, this will fail silently at runtime rather than failing fast.

Consider validating the response shape or at least adding a defensive check:

♻️ Proposed fix to add defensive validation
-    return await response.json() as { content: Array<{ type: string, text?: string }> };
+    const json = await response.json();
+    if (!json || !Array.isArray(json.content)) {
+      throw new Error('Invalid response shape from docs-tools API');
+    }
+    return json as { content: Array<{ type: string, text?: string }> };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/src/app/mcp-browser/page.tsx` at line 50, The current return uses an
unsafe cast on response.json() which bypasses type safety; replace the direct
"return await response.json() as { content: Array<{ type: string, text?: string
}> }" with a defensive parse/validation: call response.json(), verify
response.ok, ensure the parsed value has a "content" property that's an array,
and that each item has a string "type" and optional string "text"; if validation
fails, throw a descriptive error (or return a safe fallback). Consider
extracting this into a small helper (e.g., validateApiResponse or
parseResponseFromApi) so callers use a typed, validated object instead of the
unsafe cast.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/backend/src/lib/ai/tools/docs.ts`:
- Around line 32-36: The fetch to `${base}/api/internal/docs-tools` needs an
explicit timeout: wrap the request in an AbortController, pass controller.signal
into the fetch options used in the const res = await fetch(...) call in docs
tool function, start a setTimeout that calls controller.abort() after a
reasonable ms (e.g., 5s), and clear the timeout when fetch completes; catch the
abort error and throw or return a bounded tool-specific error (e.g.,
"DocsToolTimeoutError" or a descriptive error message) so the caller of the docs
tool (the AI tool path) can surface a bounded timeout response instead of
waiting for the underlying network/socket timeout.
- Around line 43-50: The function currently treats a 200 response with no usable
text as success; instead validate the parsed DocsToolHttpResult payload and fail
loudly: after parsing (the variable data) and computing text, if text is an
empty string (no text items found) then throw an Error (include context like the
raw data or a descriptive message) rather than returning "" or "Unknown docs
tool error"; keep the existing branch that returns when data.isError === true
but add this explicit validation/throw for missing text to surface contract
drift between the docs app and backend tools.

In `@docs/src/app/api/internal/`[transport]/route.ts:
- Around line 81-98: The capabilities object uses the camelCase key askStackAuth
which doesn't match the registered tool name ask_stack_auth and will cause
"Unknown tool" runtime errors; update the capabilities key from askStackAuth to
ask_stack_auth so it exactly matches the registered tool name (referencing the
registered tool identifier ask_stack_auth and the capabilities entry
askStackAuth in route.ts), ensuring the MCP adapter can invoke the tool.

In `@docs/src/app/api/search/route.ts`:
- Around line 12-24: The helper callDocsToolsSearch should not build a backend
target from the untrusted requestOrigin and swallow failures; instead invoke the
docs-tools operation directly (call the internal handler/function exported by
docs/src/app/api/internal/docs-tools/route.ts) or use a trusted server base URL
and include the STACK_INTERNAL_DOCS_TOOLS_SECRET in the request so auth failures
surface; remove the broad try-catch that returns [] on error and let errors
propagate (or throw a specific error) so failures are loud; apply the same fixes
to the other similar fetches around the result_limit lines referenced (79-82 and
107-109) and ensure the call includes the secret header when using an HTTP
request.
- Around line 116-119: The current comparator in sortedResults reorders results
solely by getPlatformPriority, which overrides upstream relevance from
callDocsToolsSearch; update the sort to preserve upstream relevance and only use
platform priority as a tie-breaker: when sorting filteredResults, first compare
the upstream relevance score (use the score/relevance property returned by
callDocsToolsSearch if present), if equal compare getPlatformPriority(a.url) vs
getPlatformPriority(b.url), and finally fall back to original index to ensure a
stable sort (e.g., attach the original index before sorting). Ensure you
reference filteredResults, sortedResults, callDocsToolsSearch, and
getPlatformPriority when making the change.

In `@docs/src/lib/docs-tools-operations.ts`:
- Around line 413-415: The handler for "search_docs" must sanitize and clamp
input.result_limit before it's used (and before any slice(0, result_limit)
calls) to avoid negative values like -1 turning into slice(0, -1); normalize to
an integer (e.g., parse/Number), enforce a minimum of 0, and apply a sensible
maximum cap (e.g., 100) before passing it into searchDocsImpl or using it in
array slicing; update the code around input.result_limit, the call to
searchDocsImpl, and any downstream slice() usage to use this
clampedPositiveLimit instead of the raw input.value.
- Around line 239-305: The search currently scans allPages and calls readFile
per page inside the loop (see variables allPages, readFile, and textContent)
causing a full disk read on each request; fix by extracting the file-reading and
normalization logic into a precomputed in-memory search index (e.g.,
buildSearchIndex or cachedPages map) that runs at startup or on content changes,
store normalized text, titles, descriptions and toc for each page, and update
the search routine to iterate that in-memory index instead of reading files;
ensure docs/src/app/api/search/route.ts uses the cached index and add
invalidation/update hooks when content changes.

---

Nitpick comments:
In `@docs/src/app/api/internal/`[transport]/route.ts:
- Around line 59-70: The code unsafely casts the fetch response to a specific
shape using "as { finalText?, content? }" when computing the "body" and "text"
variables in route.ts; replace this with runtime validation: after awaiting
res.json(), check res.ok and that the parsed value is an object, then validate
that body.finalText (if present) is a string or that body.content is an array
whose items have type === "text" and text is a string before using them to build
"text"; if validation fails, handle the error path (log or throw) and fall back
to "" (or a safe default). If your codebase uses a runtime schema validator
(e.g., zod), validate the response against a schema instead of the assertion;
update all uses of "body" and the "text" assembly accordingly.

In `@docs/src/app/mcp-browser/page.tsx`:
- Line 50: The current return uses an unsafe cast on response.json() which
bypasses type safety; replace the direct "return await response.json() as {
content: Array<{ type: string, text?: string }> }" with a defensive
parse/validation: call response.json(), verify response.ok, ensure the parsed
value has a "content" property that's an array, and that each item has a string
"type" and optional string "text"; if validation fails, throw a descriptive
error (or return a safe fallback). Consider extracting this into a small helper
(e.g., validateApiResponse or parseResponseFromApi) so callers use a typed,
validated object instead of the unsafe cast.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f12ae57-f536-4ae7-856b-6955f080d5e7

📥 Commits

Reviewing files that changed from the base of the PR and between 3efb226 and 30d53e8.

📒 Files selected for processing (12)
  • apps/backend/.env.development
  • apps/backend/src/app/api/latest/ai/query/[mode]/route.ts
  • apps/backend/src/lib/ai/tools/docs.ts
  • claude/CLAUDE-KNOWLEDGE.md
  • docs/.env.development
  • docs/content/docs/(guides)/others/mcp-setup.mdx
  • docs/src/app/api/internal/[transport]/route.ts
  • docs/src/app/api/internal/[transport]/setup-instructions.md
  • docs/src/app/api/internal/docs-tools/route.ts
  • docs/src/app/api/search/route.ts
  • docs/src/app/mcp-browser/page.tsx
  • docs/src/lib/docs-tools-operations.ts

- Introduced error capturing for failed HTTP requests in the docs tools API, improving debugging capabilities.
- Updated the API response for unsupported methods to include an 'Allow' header, clarifying the expected request type.

These changes enhance the robustness of the documentation tools integration and improve developer experience.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
apps/backend/src/lib/ai/tools/docs.ts (2)

109-118: Consider consolidating duplicate tools.

search and search_docs overlap in functionality (both search documentation). Similarly, fetch is documented as "identical to get_docs_by_id". This duplication may confuse AI models choosing between tools. If these exist for backward compatibility, consider documenting that intent.

Also applies to: 120-129

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/backend/src/lib/ai/tools/docs.ts` around lines 109 - 118, The PR defines
duplicate tools — search and search_docs (and fetch vs get_docs_by_id) — which
overlap and can confuse tool selection; consolidate by removing one alias or
explicitly mark aliases as backward-compatible. Update the tools registration in
apps/backend/src/lib/ai/tools/docs.ts: either merge search_docs into search (and
remove the duplicate tool) or keep one canonical implementation (e.g., search,
get_docs_by_id) and implement the other names as thin wrapper aliases that call
the canonical function (via postDocsToolAction) while adding clear descriptions
stating they are deprecated/backwards-compatible; also update the description
strings to mention the aliasing so AI models know these are identical.

6-9: Consider making DocsToolHttpResult stricter or adding runtime validation.

The type is permissive (all fields optional) and used with a type assertion at line 43. If the contract changes, errors will be silent. A Zod schema would provide runtime safety.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/backend/src/lib/ai/tools/docs.ts` around lines 6 - 9, DocsToolHttpResult
is too permissive and is being trusted via a type assertion elsewhere; define a
strict runtime schema (e.g., a Zod schema) that mirrors DocsToolHttpResult
(require content as array of objects with required type and optional text, and
explicit isError boolean) and validate incoming HTTP responses against that
schema instead of asserting the type; update usages where the assertion occurs
(the code that currently casts to DocsToolHttpResult) to parse/validate with the
schema, handle validation failures (treat as error/isError) and then rely on the
validated shape for downstream logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/backend/src/lib/ai/tools/docs.ts`:
- Around line 109-118: The PR defines duplicate tools — search and search_docs
(and fetch vs get_docs_by_id) — which overlap and can confuse tool selection;
consolidate by removing one alias or explicitly mark aliases as
backward-compatible. Update the tools registration in
apps/backend/src/lib/ai/tools/docs.ts: either merge search_docs into search (and
remove the duplicate tool) or keep one canonical implementation (e.g., search,
get_docs_by_id) and implement the other names as thin wrapper aliases that call
the canonical function (via postDocsToolAction) while adding clear descriptions
stating they are deprecated/backwards-compatible; also update the description
strings to mention the aliasing so AI models know these are identical.
- Around line 6-9: DocsToolHttpResult is too permissive and is being trusted via
a type assertion elsewhere; define a strict runtime schema (e.g., a Zod schema)
that mirrors DocsToolHttpResult (require content as array of objects with
required type and optional text, and explicit isError boolean) and validate
incoming HTTP responses against that schema instead of asserting the type;
update usages where the assertion occurs (the code that currently casts to
DocsToolHttpResult) to parse/validate with the schema, handle validation
failures (treat as error/isError) and then rely on the validated shape for
downstream logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e673009a-93c6-437e-8777-1827d56adf1c

📥 Commits

Reviewing files that changed from the base of the PR and between 30d53e8 and 5078747.

📒 Files selected for processing (2)
  • apps/backend/src/lib/ai/tools/docs.ts
  • docs/src/app/api/internal/docs-tools/route.ts

- Updated the key name in the capabilities section of the API documentation to follow a consistent naming convention, improving clarity and maintainability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants