Skip to content

fix(mcp): CORS middleware, renaming, error handling #9423

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

matthewmcneely
Copy link
Member

@matthewmcneely matthewmcneely commented May 22, 2025

Description

This PR:

  • Adds a CORS middleware handler to the MCP SSE server
  • Adds sanity checking for malformed MCP arguments (prevent panics)
  • Renames tools, resources and prompts to use the snake_case convention of MCP discussion
  • Uses the correct error handling for returning errors to clients
  • Adds a comprehensive integration test for the MCP SSE implementation

Note, there's a MCP demo client here that you can spin up to test the SSE implementation.

Checklist

  • Code compiles correctly and linting passes locally
  • Tests added for new functionality, or regression tests for bug fixes added as applicable

@github-actions github-actions bot added the go Pull requests that update Go code label May 22, 2025
Copy link

trunk-io bot commented May 22, 2025

Running Code Quality on PRs by uploading data to Trunk will soon be removed. You can still run checks on your PRs using trunk-action - see the migration guide for more information.

@@ -102,22 +102,22 @@ func NewMCPServer(connectionString string, readOnly bool) (*server.MCPServer, er
s.AddTool(alterSchemaTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
schema, ok := request.GetArguments()["schema"].(string)
if !ok {
return nil, fmt.Errorf("schema must be present")
return mcp.NewToolResultError("Schema must be present"), nil
Copy link
Member Author

Choose a reason for hiding this comment

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

Handling errors via mcp.NewToolResultError is the correct mode. If we return an err, the SSE server internals will return a 500 server error.

@github-actions github-actions bot added the area/testing Testing related issues label May 23, 2025
@matthewmcneely matthewmcneely marked this pull request as ready for review May 23, 2025 19:58
@matthewmcneely matthewmcneely requested a review from a team as a code owner May 23, 2025 19:58
Copy link

trunk-io bot commented May 23, 2025

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing Testing related issues go Pull requests that update Go code
Development

Successfully merging this pull request may close these issues.

1 participant