modelcontextprotocol / modelcontextprotocol/php-sdk

[Server] Expose request-level metadata (e.g., securitySchema) to tool handlers

Aperta
#159 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Server
Lingua principale
PHP
Stelle
1.6k
Fork
173
Merge medio
2g 49m
PR unite (30g)
23

Descrizione

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,
        ];
    }
}

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando il livello di dispatch degli strumenti del server e il modo in cui l’envelope della richiesta in ingresso raggiunge gli handler degli strumenti; l’issue non indica file o test specifici. Confronta l’iniezione di CallToolRequest con l’iniezione della sezione meta, quindi aggiungi una copertura che mostri che un handler può leggere securitySchema e che gli handler esistenti che usano solo parametri continuano a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
php
Ambito
api, backend
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.