-
Notifications
You must be signed in to change notification settings - Fork 111
Add MongoDB Assistant Tools #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 introduces MongoDB Assistant tools for the MCP server, enabling natural language search and knowledge source discovery. It adds integration with the MongoDB Assistant AI chatbot and search service.
- Scaffolds a new
AssistantToolBase
class for MongoDB Assistant tool interactions - Implements two initial tools:
list_knowledge_sources
andsearch_knowledge
- Adds comprehensive test coverage with mocked API responses
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/common/config.ts | Adds assistantBaseUrl configuration option |
src/tools/tool.ts | Extends ToolCategory type to include "assistant" |
src/tools/assistant/assistantTool.ts | Base class for Assistant tools with common functionality |
src/tools/assistant/list_knowledge_sources.ts | Tool for listing available knowledge sources |
src/tools/assistant/search_knowledge.ts | Tool for searching the knowledge base |
src/tools/assistant/tools.ts | Exports array of Assistant tools |
src/server.ts | Registers Assistant tools with the server |
tests/integration/helpers.ts | Updates response element types to support metadata |
tests/integration/tools/assistant/assistantHelpers.ts | Test utilities for Assistant tool testing |
tests/integration/tools/assistant/listKnowledgeSources.test.ts | Integration tests for list knowledge sources tool |
tests/integration/tools/assistant/searchKnowledge.test.ts | Integration tests for search knowledge tool |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
||
export const SearchKnowledgeToolArgs = { | ||
query: z.string().describe("A natural language query to search for in the knowledge base"), | ||
limit: z.number().min(1).max(100).optional().default(5).describe("The maximum number of results to return"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limit: z.number().min(1).max(100).optional().default(5).describe("The maximum number of results to return"), | |
limit: z.number().min(1).max(100).optional().default(10).describe("The maximum number of results to return"), |
i've seen 10 chunks in a bunch of other implementations. we dont do this in our chatbot, but that's largely for latency/price
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured this should match the default of 5
we have on our server, no? Open to changing that though.
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
args: ToolArgs<typeof this.argsShape> | ||
): TelemetryToolMetadata { | ||
return {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what if anything I should have here - would appreciate advice from the DevTools team on this.
this.baseUrl = new URL(config.assistantBaseUrl); | ||
const serverVersion = packageInfo.version; | ||
this.requiredHeaders = { | ||
"x-request-origin": "mongodb-mcp-server", | ||
"user-agent": serverVersion ? `mongodb-mcp-server/v${serverVersion}` : "mongodb-mcp-server", | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we try to use the apiClient
to make this call? do you need specific headers or can you leverage that to make requests? Check getIpInfo
in that file for a customized call
Also, is this page not authenticated?
@@ -0,0 +1,51 @@ | |||
import { z } from "zod"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could we rename the files to camelCase for consistency?
headers: this.requiredHeaders, | ||
}); | ||
if (!response.ok) { | ||
throw new Error(`Failed to list knowledge sources: ${response.statusText}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we instead return content
instead of throwing an exception? we've been changing this across the code. it's better to have the tool return a response but with the proper messaging
const searchEndpoint = new URL("content/search", this.baseUrl); | ||
const response = await fetch(searchEndpoint, { | ||
method: "POST", | ||
headers: new Headers({ ...this.requiredHeaders, "Content-Type": "application/json" }), | ||
body: JSON.stringify(args), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before, let's keep api calls under the client for proper abtraction and consistency
@@ -12,7 +12,7 @@ import type { Server } from "../server.js"; | |||
export type ToolArgs<Args extends ZodRawShape> = z.objectOutputType<Args, ZodNever>; | |||
|
|||
export type OperationType = "metadata" | "read" | "create" | "delete" | "update" | "connect"; | |||
export type ToolCategory = "mongodb" | "atlas"; | |||
export type ToolCategory = "mongodb" | "atlas" | "assistant"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we're here, can we also update the readme.md? there we call out all the tool categories
}); | ||
|
||
export class SearchKnowledgeTool extends AssistantToolBase { | ||
public name = "search_knowledge"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: all out tool names use -
instead of _
could we update them for consistency?
Proposed changes
(EAI-1266) Knowledge Search on MCP
Adds a new class of
Assistant
tools for interacting with the MongoDB Assistant (AI Chatbot + Search).This PR scaffolds the generic
AssistantToolBase
class as well as two initial tools:list_knowledge_sources
- pulls a list of all available data sources. Useful for knowing what data is available and for filtering thesearch_knowledge
search_knowledge
- runs a natural language search against the MongoDB Assistant knowledge base. Returns content chunks for the most relevant results.Checklist