Skip to content

task: add _meta field to relevant types as defined in MCP specification #429

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

Merged
merged 1 commit into from
Aug 3, 2025

Conversation

buraksenn
Copy link
Contributor

@buraksenn buraksenn commented Jun 20, 2025

Description

This PR adds _meta field to relevant types

Fixes #416

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • MCP spec compatibility implementation
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Tests only (no functional changes)
  • Other (please describe):

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly

MCP Spec Compliance

Summary by CodeRabbit

  • New Features

    • Introduced a structured metadata field across various resources, tools, prompts, and content types, allowing for additional metadata to be included where supported.
  • Bug Fixes

    • Improved consistency in how metadata is processed and stored, reducing the risk of errors related to metadata handling.
  • Tests

    • Updated tests to reflect changes in metadata handling and ensure continued reliability.

Copy link
Contributor

coderabbitai bot commented Jun 20, 2025

Walkthrough

The changes introduce an optional Meta field of type pointer to Meta across several key structs in the MCP package, including Prompt, Tool, Resource, and other resource/content types. The code also standardizes metadata handling by replacing raw map usage with the Meta struct and updates related parsing and test logic accordingly.

Changes

Files/Paths Change Summary
mcp/types.go Added Meta *Meta field to multiple structs (Resource, ResourceTemplate, TextResourceContents, BlobResourceContents, TextContent, ImageContent, AudioContent, EmbeddedResource, Root). Introduced NewMetaFromMap constructor. Changed Result.Meta type from map[string]any to *Meta.
mcp/prompts.go, mcp/tools.go Added optional Meta *Meta field to Prompt and Tool structs, serialized as _meta in JSON.
mcp/utils.go Updated parsing functions to use NewMetaFromMap for constructing the Meta field from maps.
server/sse_test.go Updated test to assign Meta via NewMetaFromMap instead of direct map assignment.

Assessment against linked issues

Objective Addressed Explanation
Add _meta field to Resource, Tool, Prompt, and other interface types (#416)
Update JSON marshaling to handle _meta properly (#416)
Add documentation about _meta usage (#416) Documentation changes are not present in the code changes.
Ensure _meta is reserved for protocol use (#416)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested labels

type: enhancement, area: mcp spec

Suggested reviewers

  • ezynda3
  • pottekkat

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
mcp/types.go (1)

153-163: Consider input map mutation side effect.

The function modifies the input map by deleting the "progressToken" key, which could be unexpected for callers. Consider making a copy of the input map first to avoid side effects.

 func NewMetaFromMap(m map[string]any) *Meta {
+	// Create a copy to avoid modifying the input map
+	mapCopy := make(map[string]any)
+	for k, v := range m {
+		mapCopy[k] = v
+	}
+	
-	progressToken := m["progressToken"]
+	progressToken := mapCopy["progressToken"]
 	if progressToken != nil {
-		delete(m, "progressToken")
+		delete(mapCopy, "progressToken")
 	}

 	return &Meta{
 		ProgressToken:    progressToken,
-		AdditionalFields: m,
+		AdditionalFields: mapCopy,
 	}
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0fdb197 and bf6d4de.

📒 Files selected for processing (5)
  • mcp/prompts.go (1 hunks)
  • mcp/tools.go (1 hunks)
  • mcp/types.go (11 hunks)
  • mcp/utils.go (3 hunks)
  • server/sse_test.go (1 hunks)
🔇 Additional comments (7)
mcp/prompts.go (1)

46-47: LGTM! Clean implementation following MCP specification.

The addition of the Meta field to the Prompt struct is well-implemented:

  • Uses pointer type for optional metadata
  • Correct JSON tag _meta,omitempty aligns with MCP specification
  • Proper documentation explaining the field's purpose
  • No breaking changes since the field is optional
mcp/tools.go (1)

473-474: LGTM! Consistent with other MCP specification changes.

The Meta field addition to the Tool struct follows the same clean pattern as in Prompt:

  • Consistent use of *Meta pointer type
  • Proper _meta,omitempty JSON tagging
  • Good documentation alignment with MCP specification
  • Maintains consistency across the codebase
mcp/utils.go (2)

598-598: Consistent metadata handling across parsing functions.

Both ParseCallToolResult and ParseReadResourceResult follow the same clean pattern as ParseGetPromptResult, ensuring consistent metadata handling across the entire codebase.

Also applies to: 680-680


532-532: Good refactoring to structured metadata handling.

The update to use NewMetaFromMap(metaMap) improves type safety and consistency with the new Meta struct approach.

Verify that the NewMetaFromMap function properly handles edge cases like nil maps and invalid data:

#!/bin/bash
# Description: Search for NewMetaFromMap function definition and its error handling

# Search for the NewMetaFromMap function definition
ast-grep --pattern 'func NewMetaFromMap($$$) $$$'

# Search for any error handling in NewMetaFromMap
rg -A 10 "func NewMetaFromMap"
server/sse_test.go (1)

1260-1260: Good test update maintaining consistency with new metadata handling.

The test correctly adopts the new mcp.NewMetaFromMap pattern while preserving its original purpose of testing JSON marshaling errors. This ensures test code stays consistent with the production code changes.

mcp/types.go (2)

246-246: Breaking change acknowledged for MCP specification compliance.

The change from map[string]any to *Meta is a breaking change but expected for MCP specification compatibility. This aligns with the structured metadata approach being implemented across the codebase.


650-651: Systematic Meta field addition follows consistent pattern.

The addition of Meta *Meta fields with "_meta,omitempty" JSON tags across all relevant structs is well-implemented and follows a consistent pattern. The comments are uniform and the implementation aligns with the MCP specification requirements.

Also applies to: 676-677, 707-708, 721-722, 855-856, 868-869, 883-884, 916-917, 1050-1051

@Crescent617
Copy link

When will this PR be merged?

@ezynda3 ezynda3 merged commit 57740b6 into mark3labs:main Aug 3, 2025
4 checks passed
@buraksenn buraksenn deleted the add-meta-field-to-types branch August 4, 2025 07:36
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.

Task: Add _meta Field to Interface Types
3 participants