- Newest
- Most votes
- Most comments
When working with Amazon Bedrock AgentCore and MCP (Model Context Protocol) servers, you can pass custom headers from your frontend to the MCP server and read them within your application.
For passing custom headers to your MCP server deployed in AgentCore, you need to include them in the headers dictionary when creating your HTTP client connection. Based on the example code for connecting to an MCP server, you can modify the headers dictionary to include your custom headers:
headers = { "authorization": f"Bearer {bearer_token}", "Content-Type": "application/json", "x-my-custom-id-token": "your-id-token-here" # Add your custom header here }
When making HTTP requests to AWS IoT Core or other AWS services, you can pass credentials and custom information through request headers. The header names are case-insensitive, but it's a good practice to follow consistent naming conventions.
For reading headers in your MCP server, you'll need to access the incoming HTTP request object in your server code. The exact implementation depends on the framework you're using for your MCP server. If you're using FastMCP or a similar framework, you should be able to access the request headers through the request object provided by your web framework.
If you're having issues with your custom headers not appearing in the MCP server, consider these potential issues:
-
Header stripping: Some intermediary services might strip non-standard headers. Ensure your header names follow conventions (typically prefixed with "x-" for custom headers).
-
CORS configuration: If your frontend is making cross-origin requests, ensure your CORS configuration allows the custom headers.
-
Proxy configuration: If there are API gateways or proxies between your components, ensure they're configured to pass through your custom headers.
-
Case sensitivity: While header names are technically case-insensitive, some implementations might handle them inconsistently.
For the specific case of passing an ID token from an agent to an MCP server within AgentCore, make sure both components are properly configured to handle the custom headers, and verify that the AgentCore runtime environment isn't stripping these headers during the request forwarding process.
Sources
https://docs.aws.amazon.com/embedded-csdk/202012.00/lib-ref/libraries/standard/coreHTTP/docs/doxygen/output/html/httpclient_addheader_function.html
Connecting to AWS IoT Core by using custom authentication - AWS IoT Core
Deploy MCP servers in AgentCore Runtime - Amazon Bedrock AgentCore
Relevant content
- asked 6 months ago
- asked 10 days ago
