Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion a2a/weather_service/src/weather_service/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,20 @@ async def execute(self, context: RequestContext, event_queue: EventQueue):
# Here we just run the agent logic - spans from LangChain are auto-captured
output = None

# Forward inbound Authorization header to outbound MCP tool calls.
# This enables transparent token exchange when deployed behind a waypoint
# or AuthBridge proxy (same pattern as git_issue_agent, see c8ebde1).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
# or AuthBridge proxy (same pattern as git_issue_agent, see c8ebde1).
# or [AuthBridge](https://github.com/kagenti/kagenti-extensions/tree/main/AuthBridge) proxy (same pattern as git_issue_agent, see c8ebde1).

mcp_headers = None
if context.call_context and (context.call_context.state or {}).get("headers", {}).get("authorization"):
mcp_headers = {"Authorization": context.call_context.state["headers"]["authorization"]}
logger.info("Forwarding inbound Authorization header to MCP tool calls")
else:
logger.warning("No inbound Authorization header; MCP tool calls will be unauthenticated")

# Test MCP connection first
logger.info(f"Attempting to connect to MCP server at: {os.getenv('MCP_URL', 'http://localhost:8000/sse')}")

mcpclient = get_mcpclient()
mcpclient = get_mcpclient(headers=mcp_headers)

# Try to get tools to verify connection
try:
Expand Down
18 changes: 9 additions & 9 deletions a2a/weather_service/src/weather_service/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class ExtendedMessagesState(MessagesState):
final_answer: str = ""


def get_mcpclient():
return MultiServerMCPClient(
{
"math": {
"url": os.getenv("MCP_URL", "http://localhost:8000/mcp"),
"transport": os.getenv("MCP_TRANSPORT", "streamable_http"),
}
}
)
def get_mcpclient(headers=None):
"""Create MCP client, optionally forwarding headers (e.g. Authorization)."""
mcp_config = {
"url": os.getenv("MCP_URL", "http://localhost:8000/mcp"),
"transport": os.getenv("MCP_TRANSPORT", "streamable_http"),
}
if headers:
mcp_config["headers"] = headers
return MultiServerMCPClient({"math": mcp_config})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return MultiServerMCPClient({"math": mcp_config})
return MultiServerMCPClient({"weather": mcp_config})

This isn't your fault, but some (generated?) code is calling weather a math tool.



async def get_graph(client) -> StateGraph:
Expand Down
Loading