[Server] Expose request-level metadata (e.g., securitySchema) to tool handlers
还没有人认领这个 Issue。
评估
调研方向
首先跟踪服务器的工具分发层,以及传入的请求信封如何到达工具处理器;该 issue 未指定具体的文件或测试。比较注入 CallToolRequest 与注入 meta 部分,然后添加覆盖,展示处理器可以读取 securitySchema,并且现有的仅使用参数的处理器仍能正常工作。
由索引模型根据 Issue 内容生成。
描述
Is your feature request related to a problem? Please describe.
Tool handlers currently receive only the parameters defined for the tool call.
Metadata included in the request envelope (for example a securitySchema) is not available inside the handler.
This makes it impossible to perform logic that depends on contextual information from the request itself.
Describe the solution you’d like
A way for tool handlers to access the metadata from the incoming request envelope.
This could be done by injecting either the full request object or just the meta section into the handler method.
Having this information available would allow tools to perform authorization checks, tenant selection, and similar context-dependent actions.
Describe alternatives you’ve considered
The only workaround at the moment is extracting envelope metadata before the request reaches the tool dispatching layer and storing it somewhere manually.
Once inside the handler, that information can no longer be accessed in a clean or reliable way.
Additional context
A common use case is reading a securitySchema sent by the client.
This information is part of the envelope, not part of the tool parameters, and is therefore currently inaccessible inside tool logic.
What tool handlers currently look like
use MCP\Server\Attributes\McpTool;
final class ExampleTools
{
#[McpTool(name: 'example_action')]
public function exampleAction(string $input): array
{
// Only defined parameters are available.
// Envelope metadata (e.g., securitySchema) cannot be accessed here.
return ['result' => 'ok'];
}
}
Proposed Option A — Inject full request object
use MCP\Server\Attributes\McpTool;
use MCP\Types\CallToolRequest;
final class ExampleTools
{
#[McpTool(name: 'example_action')]
public function exampleAction(
string $input,
CallToolRequest $request,
): array {
$meta = $request->meta ?? null;
$schema = $meta['securitySchema'] ?? null;
return [
'result' => 'ok',
'securitySchema' => $schema,
];
}
}
Proposed Option B — Inject only the meta section
use MCP\Server\Attributes\McpTool;
final class ExampleTools
{
#[McpTool(name: 'example_action')]
public function exampleAction(
string $input,
array $meta = [],
): array {
$schema = $meta['securitySchema'] ?? null;
return [
'result' => 'ok',
'securitySchema' => $schema,
];
}
}
- 主要语言
- PHP
- 星标
- 1.6k
- 派生
- 173
- 平均合并
- 2 天 20 小时
- 30 天内合并 PR
- 14
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/php-sdk 的其他 Issue
-
[Server] Handler type uses bare Closure, hard to decorate RegistryInterface under strict PHPStan 未关闭Server
难度 1/5 1 小时以内 新手友好度 78/100
modelcontextprotocol/php-sdk#468 · 2 条评论 ·
-
needs confirmation needs maintainer action Server
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/php-sdk#398 · 1 个 reaction ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/php-sdk#370 ·
-
难度 3/5 1-2 天 新手友好度 65/100
modelcontextprotocol/php-sdk#513 ·
-
enhancement
难度 4/5 3-5 天 新手友好度 55/100
modelcontextprotocol/php-sdk#510 · 1 条评论 ·
查看 modelcontextprotocol/php-sdk 的全部 Issue
相似的 Issue
-
tooling
难度 2/5 1-3 小时 新手友好度 75/100
-
UX
难度 2/5 1-3 小时 新手友好度 70/100
ProfessionalWiki/NeoWiki#1525 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 1/5 1 小时以内 新手友好度 90/100
OpenConext/OpenConext-engineblock#2122 ·
-
Bug
难度 2/5 1-3 小时 新手友好度 70/100
Automattic/safe-publish#594 ·