-
Notifications
You must be signed in to change notification settings - Fork 168
chore: add developer guide and code examples to extend MCP server via library exports MCP-299 #767
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
b232a56 to
9cc5526
Compare
5d00ab6 to
64cb9bf
Compare
This commit brings back static operationType property on ToolClass declarations and ensures that current tools abides by it. Additionally we are now exporting Tools as a record instead of list to allow selective picking.
3c82e49 to
79fe868
Compare
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 adds a comprehensive developer guide documenting how to extend and embed the MongoDB MCP server as a library. The changes also refactor the tool architecture to make operationType a static class property instead of an instance property, enabling better type safety and easier tool registration.
Key Changes:
- Added detailed developer guide (
MCP_SERVER_LIBRARY.md) with working code examples - Refactored
operationTypefrom instance property to static class property across all tools - Updated tool exports to use named exports instead of arrays for better tree-shaking and selective import
- Enhanced TypeScript documentation for exported APIs
Reviewed changes
Copilot reviewed 53 out of 53 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
MCP_SERVER_LIBRARY.md |
New comprehensive developer guide with use cases and examples |
src/tools/tool.ts |
Made operationType static property; added extensive JSDoc documentation |
src/tools/index.ts |
Changed tool exports from arrays to named exports |
src/tools/mongodb/tools.ts |
Converted from array export to individual named exports |
src/tools/atlas/tools.ts |
Converted from array export to individual named exports |
src/tools/atlasLocal/tools.ts |
Converted from array export to individual named exports |
src/tools/mongodb/**/*.ts |
Updated all MongoDB tools to use static operationType |
src/tools/atlas/**/*.ts |
Updated all Atlas tools to use static operationType |
src/tools/atlasLocal/**/*.ts |
Updated all Atlas Local tools to use static operationType |
src/transports/base.ts |
Added extensive JSDoc documentation for TransportRunnerConfig |
src/server.ts |
Updated to inject static operationType during tool construction |
src/lib.ts |
Added new exports for developer-facing APIs |
tests/**/*.test.ts |
Updated tests to use static operationType and new export structure |
knip.json |
Ignored tool files due to knip limitation with named exports |
Pull Request Test Coverage Report for Build 19830106881Details
💛 - Coveralls |
| protected argsShape = this.isFeatureEnabled("search") | ||
| ? { | ||
| ...commonArgs, | ||
| embeddingParameters: zSupportedEmbeddingParametersWithInput | ||
| .optional() | ||
| .describe( | ||
| "The embedding model and its parameters to use to generate embeddings for fields with vector search indexes. Note to LLM: If unsure which embedding model to use, ask the user before providing one." | ||
| ), | ||
| } | ||
| : commonArgs; |
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.
This fixes an unexpected ZodSchema because of earlier optional empty object getting injected when feature flag was not enabled. This was caught by one of the examples in the guide where a tool call was getting rejected right away.
src/tools/index.ts
Outdated
| import * as AtlasTools from "./atlas/tools.js"; | ||
| import * as AtlasLocalTools from "./atlasLocal/tools.js"; | ||
| import * as MongoDbTools from "./mongodb/tools.js"; | ||
|
|
||
| const AllTools = [...MongoDbTools, ...AtlasTools, ...AtlasLocalTools]; | ||
| const AllTools = { | ||
| ...MongoDbTools, | ||
| ...AtlasTools, | ||
| ...AtlasLocalTools, | ||
| } as const; |
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.
Please note that we're now exporting record like exports instead of array like exports. The changes allows nitpicking of individual tools.
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 think we should export this as an array and also do:
export * from from "./mongodb/tools.js";
...This way the IDE can suggest these imports and no real nitpicking is required
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.
But it is the same?
export * from "../mongodb/tools.js"
needs to be imported as:
import { ConnectTool } from "mongodb-mcp-server/tools"
and currently you would do the same either by:
import { AllTools } from "mongodb-mcp-server/tools"
AllTools.ConnectTool
or
import { MongoDbTools } from "mongodb-mcp-server/tools"
MongoDbTools.ConnectTool
Actually with the current change, we do get per category division already which we would miss if we do:
export * from "../mongodb/tools.js"
unless we do
export * as MongoDbTools from "../mongodb/tools.js"
which then essentially is the same.
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.
Based on our discussion, I have updated the export to have individual exports alongside the list of all the tools for convenience.
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.
It's nice, I think we should just export all classes and not rely on expanding the object
Proposed changes
This PR adds a guide targeting developers, explaining how to extend the MongoDB MCP server using the exports available from the library. Includes working code examples for the following use-cases:
Most of the document was written by CoPilot, so it'd be nice to actually ready through it once. I have ensured correctness of the material particularly API reference and examples.
Please note of the following changes:
operationTypeas static property to the tool classes so that its easier for library consumers to address a few use-cases, also mentioned in the guidelines.InsertManyToolusing unexpected Zod schemaChecklist