Skip to content

Keep the private key and the headers out of inspect - #733

Open
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:keep_the_private_key_and_the_headers_out_of_inspect
Open

koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:keep_the_private_key_and_the_headers_out_of_inspect

Conversation

@koic

@koic koic commented Nov 30, 2026

Copy link
Copy Markdown
Member

Motivation and Context

inspect is what error reporters, consoles and log lines print an object with, and the default one walks every instance variable. On MCP::Client::HTTP that printed the values of the static headers:, often an API key, the userinfo and query of the URL, and the session id. On ClientCredentialsProvider it printed a private_key given as a PEM String in full. On MCP::Client::Stdio it printed the env: and the arguments given to the server process, where its API keys usually go, and on the server side IntrospectionVerifier, JWTVerifier and RequestStateSecurity printed their client secret or key. MCP::Client#inspect prints its transport, so it showed the same. InMemoryStorage already keeps the tokens and the client secret out of its inspect for this reason.

MCP::Client::HTTP#inspect now shows the header names, the URL without its userinfo and query, and whether a session is open, and ClientCredentialsProvider#inspect shows whether a key is held. Each names the class of the provider or storage it holds and prints nothing of it, since what a custom one prints is its own to decide. MCP::Client::Stdio#inspect shows the command, the number of arguments and the names of the variables, and the three server classes show whether they hold a secret or a key.

How Has This Been Tested?

test/mcp/client/http_test.rb, test/mcp/client/oauth/client_credentials_provider_test.rb, test/mcp/client/stdio_test.rb, test/mcp/server/oauth/introspection_verifier_test.rb, test/mcp/server/oauth/jwt_verifier_test.rb and test/mcp/server/request_state_security_test.rb. Against the previous library each new test finds the secret in the output.

Breaking Changes

None, unless a caller parsed the default inspect output of these classes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Test update (non-breaking change which adds or updates tests)
  • Refactoring (non-breaking change which makes things better)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • CI/build script update (update CI workflow or build scripts)

Checklist

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

## Motivation and Context

`inspect` is what error reporters, consoles and log lines print an object with, and the default one walks every instance variable.
On `MCP::Client::HTTP` that printed the values of the static `headers:`, often an API key, the userinfo and query of the URL,
and the session id. On `ClientCredentialsProvider` it printed a `private_key` given as a PEM String in full.
On `MCP::Client::Stdio` it printed the `env:` and the arguments given to the server process, where its API keys usually go,
and on the server side `IntrospectionVerifier`, `JWTVerifier` and `RequestStateSecurity` printed their client secret or key.
`MCP::Client#inspect` prints its transport, so it showed the same. `InMemoryStorage` already keeps the tokens and the client secret
out of its `inspect` for this reason.

`MCP::Client::HTTP#inspect` now shows the header names, the URL without its userinfo and query, and whether a session is open,
and `ClientCredentialsProvider#inspect` shows whether a key is held. Each names the class of the provider or storage it holds
and prints nothing of it, since what a custom one prints is its own to decide. `MCP::Client::Stdio#inspect` shows the command,
the number of arguments and the names of the variables, and the three server classes show whether they hold a secret or a key.

## How Has This Been Tested?

`test/mcp/client/http_test.rb`, `test/mcp/client/oauth/client_credentials_provider_test.rb`, `test/mcp/client/stdio_test.rb`,
`test/mcp/server/oauth/introspection_verifier_test.rb`, `test/mcp/server/oauth/jwt_verifier_test.rb` and `test/mcp/server/request_state_security_test.rb`.
Against the previous library each new test finds the secret in the output.

## Breaking Changes

None, unless a caller parsed the default `inspect` output of these classes.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant