Skip to content

Conversation

@blva
Copy link
Collaborator

@blva blva commented Sep 10, 2025

Proposed changes

MCP-188

  • adds validation to the atlas tool arguments and unit tests
  • updates the argShape format to match other mongodb tools

Future improvements

  • improve args to reuse them across tools
  • add integration test coverage with validateThrowsForInvalidArguments, a PR is in progress but separated from this one

Test

Screenshot 2025-09-10 at 22 31 21

Checklist

@blva blva marked this pull request as ready for review September 11, 2025 08:19
@blva blva requested a review from a team as a code owner September 11, 2025 08:19
Copilot AI review requested due to automatic review settings September 11, 2025 08:19
Copy link
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 adds comprehensive argument validation for Atlas tools using Zod schemas to improve type safety and input validation. The changes replace direct Zod imports with a centralized args system that provides validation for common MongoDB Atlas resource types like ObjectIds, cluster names, usernames, and IP addresses.

  • Centralizes argument validation into reusable schema definitions in src/tools/args.ts
  • Updates all Atlas tools to use the new validation system instead of direct Zod imports
  • Adds comprehensive unit tests covering various validation scenarios and edge cases

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/args.test.ts Comprehensive test suite for argument validation schemas
src/tools/args.ts Central argument validation definitions using Zod schemas
src/tools/atlas/read/*.ts Updated to use centralized argument validation
src/tools/atlas/create/*.ts Updated to use centralized argument validation
src/tools/atlas/connect/connectCluster.ts Updated to use centralized argument validation
src/tools/atlas/atlasTool.ts Import reorganization for tool base class

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

Looks good, minor suggestions/questions from me. I haven't verified that the validations we've added match the ones in Atlas, so might be a good idea to double check we're not being overly restrictive with any of them.

import { AtlasArgs } from "../../args.js";

export const InspectClusterArgs = {
projectId: AtlasArgs.projectId().describe("Atlas project ID"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

The descriptions of projectId and clusterName seem to be the same everywhere - should we just include them in the AtlasArgs helpers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately they differ with some extra tiny context per tool, I added this as a future improvement to keep the scope of the task


const ALLOWED_PROJECT_NAME_CHARACTERS_REGEX = /^[a-zA-Z0-9\s()@&+:._',-]+$/;
export const ALLOWED_PROJECT_NAME_CHARACTERS_ERROR =
"Project names can't be longer than 64 characters and can only contain letters, numbers, spaces, and the following symbols: ( ) @ & + : . _ - ' ,";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

went into atlas UI and copied the exact same validation text

@blva blva requested a review from nirinchev September 11, 2025 14:01
Copy link
Collaborator

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

Looks good - mostly minor nits from me.

@coveralls
Copy link
Collaborator

coveralls commented Sep 11, 2025

Pull Request Test Coverage Report for Build 17649734141

Details

  • 143 of 143 (100.0%) changed or added relevant lines in 13 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 81.51%

Files with Coverage Reduction New Missed Lines %
src/common/connectionManager.ts 6 87.78%
Totals Coverage Status
Change from base Build 17647912778: 0.2%
Covered Lines: 4862
Relevant Lines: 5866

💛 - Coveralls

@blva blva merged commit 17b544b into main Sep 11, 2025
17 checks passed
@blva blva deleted the MCP-188 branch September 11, 2025 15:45
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.

6 participants