Open
Description
Question
I am using aws strands-agents as a client, I am passing to the streamablehttp_client(url,headers={"Authorization": "Bearer <token>"})
I want to pass the bearer token to the server and once the token is validated, i choose the appropriate tools for the server. Basically depending on the token, if it were authorized as an admin, I would add more tools to the server than if it were authorized as a normal user.
How would I be able to access the sent token from the server side?
Additional Context
Client Code
from strands.models import BedrockModel
from mcp.client.streamable_http import streamablehttp_client
from strands.tools.mcp.mcp_client import MCPClient
from strands import Agent
def create_streamable_http_transport():
return streamablehttp_client("http://localhost:8000/mcp/",headers={"Authorization": "Bearer <token>"})
bedrockmodel = BedrockModel(
model_id="us.anthropic.claude-3-5-sonnet-20240620-v1:0",
temperature=0.7,
streaming=True,
)
client = MCPClient(create_streamable_http_transport)
with client:
tools = client.list_tools_sync()
agent = Agent(tools=tools,model=bedrockmodel)
prompt = "What is MCP?"
agent(prompt)
Server Code
from mcp.server.fastmcp import FastMCP
server = FastMCP()
@server.tool(description="Use for informative question.")
def search() -> str:
return "The Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you're building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need."
server.run(transport="streamable-http")