Skip to content

Conversation

@robinevers93
Copy link
Contributor

Hello!

I'm writing an MCP server which has a requirement to do an auth check on each tool call.
The recommended way to implement this is by letting the MCP client handle obtaining the token, and passing the token from the MCP client to the MCP server through the header.

I have implemented a proposed solution to provide support in chimp for this. There are two main changes in my suggestion:

  1. The mcpEndpoint method takes an optional name of the header (defaulted to no header).
  2. A handleWithHeader method is added in which the logic takes in the value of the header as a parameter.

I included unit tests for my changed and added an example on how it can be used.

I also recorded a video to show it working, I'll attach it to the PR.

chimp-with-header-propagation.mov

Thanks a lot for considering this PR!

@adamw
Copy link
Member

adamw commented Jul 14, 2025

Thanks! I wonder if there might be situations, where multiple headers might be needed? Then, maybe we could simply pass a Seq[Header] (obtained via extractFromRequest(_.headers))?

Also, some of the in-code comments have been removed, is that on purpose?

Finally, at least a short mention in the readme would be great :)

@robinevers93
Copy link
Contributor Author

Great points, I shall make those changes and push them up, thank you!

@robinevers93
Copy link
Contributor Author

Okay, I have made those changes. Since we're using the Header type rather than the String type now, it became unnecessary to pass in a list of header names to def mcpEndpoint, as the tool logic can filter on the name if this is required.

Attaching a new video which shows the logic working using this approach.

updated-chimp-header-handling.mov

@adamw adamw merged commit ef533e4 into softwaremill:master Jul 15, 2025
5 checks passed
@adamw
Copy link
Member

adamw commented Jul 15, 2025

Awesome, thanks! :)

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.

2 participants