Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"vitest": "^3.2.4"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.22.0",
"@modelcontextprotocol/sdk": "^1.24.2",
"@mongodb-js/device-id": "^0.3.1",
"@mongodb-js/devtools-proxy-support": "^0.5.3",
"@mongosh/arg-parser": "^3.19.0",
Expand Down
25 changes: 14 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/elicitation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ElicitRequest } from "@modelcontextprotocol/sdk/types.js";
import type { ElicitRequestFormParams } from "@modelcontextprotocol/sdk/types.js";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";

export class Elicitation {
Expand Down Expand Up @@ -37,7 +37,7 @@ export class Elicitation {
* The schema for the confirmation question.
* TODO: In the future would be good to use Zod 4's toJSONSchema() to generate the schema.
*/
public static CONFIRMATION_SCHEMA: ElicitRequest["params"]["requestedSchema"] = {
public static CONFIRMATION_SCHEMA: ElicitRequestFormParams["requestedSchema"] = {
type: "object",
properties: {
confirmation: {
Expand Down
11 changes: 4 additions & 7 deletions src/tools/atlas/atlasTool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { AtlasMetadata } from "../../telemetry/types.js";
import { ToolBase, type ToolArgs, type ToolCategory } from "../tool.js";
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
Expand Down Expand Up @@ -83,17 +82,15 @@ For more information on Atlas API access roles, visit: https://www.mongodb.com/d
* @returns The tool metadata
*/
protected resolveTelemetryMetadata(
result: CallToolResult,
...args: Parameters<ToolCallback<typeof this.argsShape>>
args: ToolArgs<typeof this.argsShape>,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
{ result }: { result: CallToolResult }
): AtlasMetadata {
const toolMetadata: AtlasMetadata = {};
if (!args.length) {
return toolMetadata;
}

// Create a typed parser for the exact shape we expect
const argsShape = z.object(this.argsShape);
const parsedResult = argsShape.safeParse(args[0]);
const parsedResult = argsShape.safeParse(args);

if (!parsedResult.success) {
this.session.logger.debug({
Expand Down
11 changes: 4 additions & 7 deletions src/tools/atlas/connect/connectCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { AtlasClusterConnectionInfo } from "../../../common/connectionManag
import { getDefaultRoleFromConfig } from "../../../common/atlas/roles.js";
import { AtlasArgs } from "../../args.js";
import type { ConnectionMetadata } from "../../../telemetry/types.js";
import type { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";

const addedIpAccessListMessage =
"Note: Your current IP address has been added to the Atlas project's IP access list to enable secure connection.";
Expand All @@ -33,9 +32,7 @@ export class ConnectClusterTool extends AtlasToolBase {
public name = "atlas-connect-cluster";
protected description = "Connect to MongoDB Atlas cluster";
static operationType: OperationType = "connect";
protected argsShape = {
...ConnectClusterArgs,
};
protected argsShape = ConnectClusterArgs;

private queryConnection(
projectId: string,
Expand Down Expand Up @@ -321,10 +318,10 @@ export class ConnectClusterTool extends AtlasToolBase {
}

protected override resolveTelemetryMetadata(
result: CallToolResult,
...args: Parameters<ToolCallback<typeof this.argsShape>>
args: ToolArgs<typeof this.argsShape>,
{ result }: { result: CallToolResult }
): ConnectionMetadata {
const parentMetadata = super.resolveTelemetryMetadata(result, ...args);
const parentMetadata = super.resolveTelemetryMetadata(args, { result });
const connectionMetadata = this.getConnectionInfoMetadata();
if (connectionMetadata && connectionMetadata.project_id !== undefined) {
// delete the project_id from the parent metadata to avoid duplication
Expand Down
8 changes: 3 additions & 5 deletions src/tools/atlas/read/getPerformanceAdvisor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { AtlasToolBase } from "../atlasTool.js";
import type { CallToolResult, ServerNotification, ServerRequest } from "@modelcontextprotocol/sdk/types.js";
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import type { OperationType, ToolArgs } from "../../tool.js";
import { formatUntrustedData } from "../../tool.js";
import {
Expand All @@ -13,7 +13,6 @@ import {
SLOW_QUERY_LOGS_COPY,
} from "../../../common/atlas/performanceAdvisorUtils.js";
import { AtlasArgs } from "../../args.js";
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
import type { PerfAdvisorToolMetadata } from "../../../telemetry/types.js";

const PerformanceAdvisorOperationType = z.enum([
Expand Down Expand Up @@ -134,12 +133,11 @@ export class GetPerformanceAdvisorTool extends AtlasToolBase {
}

protected override resolveTelemetryMetadata(
result: CallToolResult,
args: ToolArgs<typeof this.argsShape>,
extra: RequestHandlerExtra<ServerRequest, ServerNotification>
{ result }: { result: CallToolResult }
): PerfAdvisorToolMetadata {
return {
...super.resolveTelemetryMetadata(result, args, extra),
...super.resolveTelemetryMetadata(args, { result }),
operations: args.operations,
};
}
Expand Down
20 changes: 13 additions & 7 deletions src/tools/atlasLocal/atlasLocalTool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import type { ToolArgs, ToolCategory } from "../tool.js";
import type { ToolArgs, ToolCategory, ToolExecutionContext } from "../tool.js";
import { ToolBase } from "../tool.js";
import type { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { Client } from "@mongodb-js/atlas-local";
import { LogId } from "../../common/logger.js";
import type { ConnectionMetadata } from "../../telemetry/types.js";
Expand All @@ -15,7 +14,11 @@ export abstract class AtlasLocalToolBase extends ToolBase {
return this.session.atlasLocalClient !== undefined && super.verifyAllowed();
}

protected async execute(...args: Parameters<ToolCallback<typeof this.argsShape>>): Promise<CallToolResult> {
protected async execute(
args: ToolArgs<typeof this.argsShape>,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_context: ToolExecutionContext
): Promise<CallToolResult> {
const client = this.session.atlasLocalClient;

// If the client is not found, throw an error
Expand All @@ -38,7 +41,7 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
};
}

return this.executeWithAtlasLocalClient(client, ...args);
return this.executeWithAtlasLocalClient(args, { client });
}

private async lookupDeploymentId(client: Client, containerId: string): Promise<string | undefined> {
Expand Down Expand Up @@ -72,8 +75,8 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
}

protected abstract executeWithAtlasLocalClient(
client: Client,
...args: Parameters<ToolCallback<typeof this.argsShape>>
args: ToolArgs<typeof this.argsShape>,
context: { client: Client }
): Promise<CallToolResult>;

protected handleError(
Expand Down Expand Up @@ -119,7 +122,10 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
return super.handleError(error, args);
}

protected resolveTelemetryMetadata(result: CallToolResult): ConnectionMetadata {
protected resolveTelemetryMetadata(
_args: ToolArgs<typeof this.argsShape>,
{ result }: { result: CallToolResult }
): ConnectionMetadata {
const toolMetadata: ConnectionMetadata = {};

// Atlas Local tools set the deployment ID in the result metadata for telemetry
Expand Down
11 changes: 7 additions & 4 deletions src/tools/atlasLocal/connect/connectDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class ConnectDeploymentTool extends AtlasLocalToolBase {
};

protected async executeWithAtlasLocalClient(
client: Client,
{ deploymentName }: ToolArgs<typeof this.argsShape>
{ deploymentName }: ToolArgs<typeof this.argsShape>,
{ client }: { client: Client }
): Promise<CallToolResult> {
// Get the connection string for the deployment
const connectionString = await client.getConnectionString(deploymentName);
Expand All @@ -36,7 +36,10 @@ export class ConnectDeploymentTool extends AtlasLocalToolBase {
};
}

protected override resolveTelemetryMetadata(result: CallToolResult): ConnectionMetadata {
return { ...super.resolveTelemetryMetadata(result), ...this.getConnectionInfoMetadata() };
protected override resolveTelemetryMetadata(
args: ToolArgs<typeof this.argsShape>,
{ result }: { result: CallToolResult }
): ConnectionMetadata {
return { ...super.resolveTelemetryMetadata(args, { result }), ...this.getConnectionInfoMetadata() };
}
}
4 changes: 2 additions & 2 deletions src/tools/atlasLocal/create/createDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class CreateDeploymentTool extends AtlasLocalToolBase {
};

protected async executeWithAtlasLocalClient(
client: Client,
{ deploymentName }: ToolArgs<typeof this.argsShape>
{ deploymentName }: ToolArgs<typeof this.argsShape>,
{ client }: { client: Client }
): Promise<CallToolResult> {
const deploymentOptions: CreateDeploymentOptions = {
name: deploymentName,
Expand Down
4 changes: 2 additions & 2 deletions src/tools/atlasLocal/delete/deleteDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class DeleteDeploymentTool extends AtlasLocalToolBase {
};

protected async executeWithAtlasLocalClient(
client: Client,
{ deploymentName }: ToolArgs<typeof this.argsShape>
{ deploymentName }: ToolArgs<typeof this.argsShape>,
{ client }: { client: Client }
): Promise<CallToolResult> {
// Lookup telemetry metadata
// We need to lookup the telemetry metadata before deleting the deployment
Expand Down
7 changes: 5 additions & 2 deletions src/tools/atlasLocal/read/listDeployments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasLocalToolBase } from "../atlasLocalTool.js";
import type { OperationType } from "../../tool.js";
import type { OperationType, ToolArgs } from "../../tool.js";
import { formatUntrustedData } from "../../tool.js";
import type { Deployment } from "@mongodb-js/atlas-local";
import type { Client } from "@mongodb-js/atlas-local";
Expand All @@ -11,7 +11,10 @@ export class ListDeploymentsTool extends AtlasLocalToolBase {
static operationType: OperationType = "read";
protected argsShape = {};

protected async executeWithAtlasLocalClient(client: Client): Promise<CallToolResult> {
protected async executeWithAtlasLocalClient(
_args: ToolArgs<typeof this.argsShape>,
{ client }: { client: Client }
): Promise<CallToolResult> {
// List the deployments
const deployments = await client.listDeployments();

Expand Down
9 changes: 5 additions & 4 deletions src/tools/mongodb/create/insertMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ export class InsertManyTool extends MongoDBToolBase {
database,
collection,
documents,
embeddingParameters: providedEmbeddingParameters,
...conditionalArgs
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
const provider = await this.ensureConnected();

const embeddingParameters = this.isFeatureEnabled("search")
? (providedEmbeddingParameters as z.infer<typeof zSupportedEmbeddingParametersWithInput>)
: undefined;
let embeddingParameters: z.infer<typeof zSupportedEmbeddingParametersWithInput> | undefined;
if ("embeddingParameters" in conditionalArgs) {
embeddingParameters = conditionalArgs.embeddingParameters;
}

// Process documents to replace raw string values with generated embeddings
documents = await this.replaceRawValuesWithEmbeddingsIfNecessary({
Expand Down
5 changes: 2 additions & 3 deletions src/tools/mongodb/mongodbTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ErrorCodes, MongoDBError } from "../../common/errors.js";
import { LogId } from "../../common/logger.js";
import type { Server } from "../../server.js";
import type { ConnectionMetadata } from "../../telemetry/types.js";
import type { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";

export const DbOperationArgs = {
database: z.string().describe("Database name"),
Expand Down Expand Up @@ -119,9 +118,9 @@ export abstract class MongoDBToolBase extends ToolBase {
*/
protected resolveTelemetryMetadata(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_result: CallToolResult,
_args: ToolArgs<typeof this.argsShape>,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_args: Parameters<ToolCallback<typeof this.argsShape>>
{ result }: { result: CallToolResult }
): ConnectionMetadata {
return this.getConnectionInfoMetadata();
}
Expand Down
Loading