Skip to content

Conversation

@sambostock
Copy link
Contributor

This removes duplicate calls to add_instrumentation_data(method: ...).

Motivation and Context

handle_request already adds the method to the instrumentation data, so there is no need to repeat this. Moreover, consumers can override these anyway.

How Has This Been Tested?

This is covered by existing tests.

Breaking Changes

Types of changes

There is no visible change, just a reduction in duplicate work.

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling N/A
  • I have added or updated documentation as needed N/A

Additional context

I left behind some calls to add_instrumentation_data which could have been moved.

def read_resource_no_content(request)
  add_instrumentation_data(resource_uri: request[:uri])
  []
end

I wasn't sure if we wanted all reads to unconditionally instrument the URI.

def call_tool(request)
  tool_name = request[:name]
  tool = tools[tool_name]
  unless tool
    add_instrumentation_data(error: :tool_not_found)
    raise RequestHandlerError.new("Tool not found #{tool_name}", request, error_type: :tool_not_found)
  end

  arguments = request[:arguments]
  add_instrumentation_data(tool_name:)

  # ...
end

I wasn't sure if we wanted to unconditionally instrument the tool_name, or only instrument known tools (as we do now).

def get_prompt(request)
  prompt_name = request[:name]
  prompt = @prompts[prompt_name]
  unless prompt
    add_instrumentation_data(error: :prompt_not_found)
    raise RequestHandlerError.new("Prompt not found #{prompt_name}", request, error_type: :prompt_not_found)
  end

  add_instrumentation_data(prompt_name:)

  # ...
end

Likewise, I wasn't sure if we only want to instrument known prompts.

`handle_request` already adds the `method` to the instrumentation data,
so there is no need to repeat this. Moreover, consumers can override
these anyway.
Copy link
Member

@koic koic left a comment

Choose a reason for hiding this comment

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

I think it's reasonable to remove these calls to add_instrumentation_data, as they are redundant.

@sambostock sambostock merged commit ffa06b1 into modelcontextprotocol:main Jun 17, 2025
5 checks passed
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.

2 participants