-
Notifications
You must be signed in to change notification settings - Fork 615
Propagate McpMeta to Result types in resource read, tool call, and prompt get operations #1230
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
base: main
Are you sure you want to change the base?
Conversation
…rces Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
… tests Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
@copilot what did you discover about other SDKs? |
I investigated the TypeScript and Python SDKs: TypeScript SDK: Has an equivalent Python SDK: Similarly has a Summary: Neither SDK consistently propagates metadata to all result types. The Python SDK does it for resources but not tools. The TypeScript SDK doesn't do it for any result type. Given this inconsistency in the other SDKs and the user's specific request for this functionality, the implementation in this PR is a reasonable enhancement that enables the use case described in the issue. |
|
@copilot, can you look at the other official SDKs as well and see what they do in this area? Ruby, Rust, Swift, Kotlin, PHP, Go, etc.? |
I investigated all official MCP SDKs. Here's a summary table:
Summary: None of the official SDKs consistently propagate primitive metadata to invocation results. The Python SDK is the closest, propagating meta for resources but not for tools or prompts. All other SDKs return handler results directly without any automatic metadata propagation. |
|
Marking NO MERGE until we decide whether we want this behavior or not, given #1230 (comment) (I've not manually validated this report) @localden, any opinion? |
|
@copilot Please look again at the TypeScript SDK and answer this question: Can a server set values in the _meta of a CallToolResult that the client can then access? Please also look at the Python SDK and answer the same question. |
|
@mikekistler it's possible to do that from the c# sdk today. To make sure it's clear, the question here is specifically whether McpMeta attributes should contribute to results. |
Yes, in both SDKs a server can set TypeScript SDK:
Python SDK:
So both SDKs support server-set metadata on result types - the question in this PR is whether the SDK should automatically propagate metadata from the primitive definition ( |
|
@stephentoub I agree with your statement
So I'm a little confused by the comparisions to other SDKs. "Attributes" are a C# concept. Do we think that other languages have concepts similar to attributes and we want to be consistent with those? I would think that it is more important for the behavior of attributes in the C# SDK to be consistent with the way attributes typically work in C# and with how the specific attributes are documented. The McpMetaAttribute documentation says
So it seems reasonable (to me) to expect that McpMeta would have effect on resource read, tool call, and prompt get results. |
|
Also, my purpose in asking Copilot about the TypeScript and Python SDKs was to decipher this statement:
I don't know what Copilot thinks it means to "propogate metadata" but I think all of TypeScript, Python, and C# will allow _meta to be set in response to any request and the client can successfully access these _meta fields. |
Attributes are just a mechanism for declaratively specifying information. Decorators in typescript and python are similar. The question isn't about exactly attributes, but about each sdk's more declarative mechanisms, rather than the imperative mechanism of just writing a handler and being in full control. For example, in python, I could author a resource like: @mcp.resource(
uri="data://app-status",
name="ApplicationStatus",
description="Provides the current status of the application.",
mime_type="application/json",
tags={"monitoring", "status"},
meta={"version": "2.1", "team": "infrastructure"}
)
def get_application_status() -> str:
.... And my question is should that metadata I exposed declarativwly on the resource propagate to the results returned when reading the resource.
I don't believe any answer here is more or less consistent with attributes in general. |
[McpMeta]attribute metadata was returned inresources/list,tools/list, andprompts/listresponses but missing fromresources/read,tools/call, andprompts/getresults.Changes
ProtocolResourceTemplate.MetatoReadResourceResult.MetaProtocolTool.MetatoCallToolResult.MetaProtocolPrompt.MetatoGetPromptResult.MetaUses
??=to preserve user-provided metadata when returning result objects directly:Tests
Added 9 tests covering:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
modelcontextprotocol.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)spec.modelcontextprotocol.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.