Skip to content

[Server] Log the tool name at info for tools/call - #548

Open
aton-of-data wants to merge 1 commit into
modelcontextprotocol:mainfrom
aton-of-data:protocol-log-tool-name-at-info
Open

aton-of-data wants to merge 1 commit into
modelcontextprotocol:mainfrom
aton-of-data:protocol-log-tool-name-at-info

Conversation

@aton-of-data

Copy link
Copy Markdown
Contributor

Follow-up to #525, as @mglaman suggested in his review.

After #525 the info-level "Handling request." record carries only the method and id. CallToolHandler logs the tool name at debug only, so a server logging at INFO has no record of which tool ran. A tool name is defined by the server, not supplied by the user, so it is safe to log at info. The arguments stay at debug.

Change

src/Server/Protocol.php:261 (handleRequest()): when the request is a CallToolRequest, the info context also gets 'name' => $request->name, the same key CallToolHandler uses. Other requests log the same context as before. CHANGELOG entry added, placed next to the other Protocol and event entries so it merges into the current 0.9.0 list without a conflict.

Tests

New test: ProtocolTest::testToolCallRequestIsLoggedWithToolNameAtInfoLevel. It sends a tools/call with a secret argument and checks the info records.

  • Without the Protocol.php change it fails: Failed asserting that '[[],{"method":"tools/call","request_id":1},{"response_id":1}]' [ASCII](length: 61) contains ""method":"tools/call","request_id":1,"name":"login"" [ASCII](length: 51).
  • With the change: OK (1 test, 2 assertions)
  • Unit suite on main ae72b2c: Tests: 1649, Assertions: 4300, Skipped: 4. With the change on ae72b2c: Tests: 1650, Assertions: 4302, Skipped: 4.
  • vendor/bin/phpstan --memory-limit=-1 (2.2.17): [OK] No errors
  • vendor/bin/php-cs-fixer fix --diff --verbose --dry-run (3.95.27): Found 0 of 602 files that can be fixed

Not run: the integration and interop suites, and the conformance tests. In my sandbox the integration HTTP tests time out on initialize on main as well, so they could not tell me anything. I ran everything on PHP 8.3.6.

Branch base: this branch sits on #525's merge commit (eee5836), not on current main. My fork token can't push the workflow change from #538, so I can't bring the fork up to date. A local trial merge into main at ae72b2c applies cleanly, and the merged src/ and tests/ diff is byte-identical to the one I tested on ae72b2c above.

Built with Claude (AI) — code, test and this description; I verified everything listed above by running it.

Since payloads moved to debug level, nothing at info said which tool a
tools/call request ran: CallToolHandler only logs the name at debug. A
tool name is server-defined, not user content, so the "Handling request."
info record now carries it under the same "name" key CallToolHandler
uses, while the arguments stay at debug.

Refs modelcontextprotocol#524
Comment thread src/Server/Protocol.php
Comment on lines +263 to +265
if ($request instanceof CallToolRequest) {
$context['name'] = $request->name;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, let's not start to bring in method specific data on this level - we need a different solution or let that topic go

@chr-hertel chr-hertel added Server Issues & PRs related to the Server component needs more work Not ready to be merged yet, needs additional follow-up from the author(s). labels Oct 7, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs more work Not ready to be merged yet, needs additional follow-up from the author(s). Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants