Skip to content

Comments

Add feature support and map the CommandResult to ToolResponse#2403

Merged
Hazel-Datastax merged 9 commits intomainfrom
hazel/add-feature-and-error-response
Feb 20, 2026
Merged

Add feature support and map the CommandResult to ToolResponse#2403
Hazel-Datastax merged 9 commits intomainfrom
hazel/add-feature-and-error-response

Conversation

@Hazel-Datastax
Copy link
Contributor

@Hazel-Datastax Hazel-Datastax commented Feb 20, 2026

What this PR does:

  1. Add enable/disable feature for MCP - comment from previous PR review
  2. Convert the API response(CommandResult) to the MCP tool response.
    • If the command succeeds, the whole result will be mapped to the structuredContent. For example, the successful result from findKeyspaces
              {
              "content": [],
              "structuredContent": {
                "status": {
                  "keyspaces": [
                    "system_auth",
                    "system_schema",
                    "default_keyspacexxx",
                    "system_distributed",
                    "system",
                    "default_keyspace",
                    "system_traces",
                    "system_views",
                    "system_virtual_schema"
                  ]
                }
              },
              "isError": false
            }
      
    • If the command fails, the errors array will be mapped to the structuredContent and the status map (if any) will be mapped to the _mata. For example, the failed result from findKeyspaces:
          {
            "_meta": {},
            "isError": true,
            "structuredContent": [
              {
                "id": "f66b9ce2-a6d4-449a-bb2c-340fc81ce788",
                "family": "REQUEST",
                "scope": "SCHEMA",
                "errorCode": "MCP_FEATURE_NOT_ENABLED",
                "title": "MCP feature not enabled",
                "message": "MCP feature is not enabled for this database."
              }
            ]
          }
      

Which issue(s) this PR fixes:
Fixes NA

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

@Hazel-Datastax Hazel-Datastax marked this pull request as ready for review February 20, 2026 01:41
@Hazel-Datastax Hazel-Datastax requested a review from a team as a code owner February 20, 2026 01:41
@Hazel-Datastax Hazel-Datastax changed the title add feature support and map the CommandResult to ToolResponse Add feature support and map the CommandResult to ToolResponse Feb 20, 2026
Copy link
Contributor

@tatu-at-datastax tatu-at-datastax 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, only question is whether we should use SchemaException or something else - I guess the main alternative would be DatabaseException.

I am fine with either choice, as long as it's conscious decision, so approving the pr.

Copy link
Contributor

@amorton amorton left a comment

Choose a reason for hiding this comment

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

looks like a good start here, things are getting cleaner :)

.map(
result -> {
// Success: structuredContent = the whole result data payload
if (result.errors() == null || result.errors().isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about partial failure for an insertMany in parallel, cannot remember if we put the errors in here or not. It was documented.

Also, we can have status and data. e.g. findOneAndUpdate return is

{
    "data": {
        "document": {
            "_id": "Inception",
            "name": "Inception",
            "genre": "Science Fiction",
            "artist": [
                "Leonardo DiCaprio"
            ],
            "status": "active"
        }
    },
    "status": {
        "matchedCount": 1,
        "modifiedCount": 1
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

partial failure for an insertMany:

{
    "status": {
        "documentResponses": [
            {
                "_id": 1,
                "status": "OK"
            },
            {
                "_id": 1,
                "status": "ERROR",
                "errorsIdx": 0
            },
            {
                "_id": 3,
                "status": "OK"
            },
            {
                "_id": 4,
                "status": "OK"
            }
        ]
    },
    "errors": [
        {
            "id": "3a6fcead-7278-4334-926d-adab60624f35",
            "family": "REQUEST",
            "scope": "DOCUMENT",
            "errorCode": "DOCUMENT_ALREADY_EXISTS",
            "title": "Document the given _id already exists",
            "message": "Cannot insert the document: a document already exists with given '_id' (1). \n\nEither resend the command with distinct '_id', or use an update command instead.",
            "documentIds": [
                1
            ]
        }
    ]
}

It should be fine in this case? Map "errors" to "structuredContent" and "status" to "_meta"

For findOneAndUpdate case, I'm going to merge the PR now and handle it later - cause I cannot test it now :)

Base automatically changed from hazel/mcp-general-command to main February 20, 2026 19:13
…-error-response

# Conflicts:
#	src/main/java/io/stargate/sgv2/jsonapi/api/v1/mcp/GeneralCommandTools.java
#	src/main/java/io/stargate/sgv2/jsonapi/api/v1/mcp/McpResource.java
@github-actions
Copy link
Contributor

📉 Unit Test Coverage Delta vs Main Branch

Metric Value
Main Branch 50.17%
This PR 50.15%
Delta 🔴 -0.02%
⚠️ Coverage decreased

@github-actions
Copy link
Contributor

Unit Test Coverage Report

Overall Project 50.15% -0.07% 🍏
Files changed 16.87%

File Coverage
SchemaException.java 100% 🍏
ApiFeature.java 86.05% 🍏
GeneralCommandTools.java 0% 🍏
McpResource.java 0% -46.94%

@github-actions
Copy link
Contributor

📉 Integration Test Coverage Delta vs Main Branch (dse69-it)

Metric Value
Main Branch 70.62%
This PR 70.58%
Delta 🔴 -0.04%
⚠️ Coverage decreased

@github-actions
Copy link
Contributor

Integration Test Coverage Report (dse69-it)

Overall Project 70.58% -0.07% 🍏
Files changed 16.87%

File Coverage
SchemaException.java 100% 🍏
ApiFeature.java 89.53% 🍏
GeneralCommandTools.java 0% 🍏
McpResource.java 0% -46%

@github-actions
Copy link
Contributor

📉 Integration Test Coverage Delta vs Main Branch (hcd-it)

Metric Value
Main Branch 72.37%
This PR 72.32%
Delta 🔴 -0.04%
⚠️ Coverage decreased

@github-actions
Copy link
Contributor

Integration Test Coverage Report (hcd-it)

Overall Project 72.32% -0.07% 🍏
Files changed 16.87%

File Coverage
SchemaException.java 100% 🍏
ApiFeature.java 89.53% 🍏
GeneralCommandTools.java 0% 🍏
McpResource.java 0% -46%

@Hazel-Datastax Hazel-Datastax merged commit e3bd407 into main Feb 20, 2026
3 checks passed
@Hazel-Datastax Hazel-Datastax deleted the hazel/add-feature-and-error-response branch February 20, 2026 20:18
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.

3 participants