powertools-lambda-python
powertools-lambda-python copied to clipboard
Feature request: MCP server event handler
Use case
i'd like to be able to write serverless MCP servers with ease and integrate all my powertools capabilities: swagger, event validation, event resolver, logger, tracing, metrics etc.
Solution/User Experience
I'd like to have UX like in https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/#response-auto-serialization but combined with the official python SDK for MCP server with all the right config to make it work on a lambda.
# server.py
from aws_lambda_powertools.event_handler import MCPResolver
mcp = MCPResolver('myMcp)
# Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
# Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
"""Get a personalized greeting"""
return f"Hello, {name}!"
# You can continue to use other utilities just as before
@logger.inject_lambda_context()
@tracer.capture_lambda_handler
def lambda_handler(event: dict, context: LambdaContext) -> dict:
return mcp.resolve(event, context)
Alternative solutions
use unknown open sources like MCPEngine and build my own wrappers for logging/tracer.. i want the powertools edition :)
Acknowledgment
- [x] This feature request meets Powertools for AWS Lambda (Python) Tenets
- [x] Should this be considered in other Powertools for AWS Lambda languages? i.e. Java, TypeScript, and .NET
Hi @ran-isenberg, thank you for opening this feature request.
Everyone is talking about MCPs these days so I am not surprised to see a feature request in this space finally arriving to our project.
I am wondering if you could share - either here or privately via email - whether there are specific use cases that you're considering at CyberArk that this MCP resolver would help with.
Also on a more technical level, I'm wondering if you had any opinions/suggestions on how we should handle authentication with this type of resolver, the spec for MCP is still very blurry around this type of concerns.
Finally, from a governance standpoint, before implementing this we'll have to discuss how to release this. The Powertools for AWS brand has certain commitments around stability and versioning (highlighted in our wiki) that I'm not sure would fit with a spec still very much in flux like MCP.
We can talk over discord if you wish, but yeah I have some ideas and needs :) As more auth/authz. When you place it behind API GW, you can use WAF, IAM auth/cognito/any JWT token authorization. See https://github.com/mikegc-aws/Lambda-MCP-Server - he added a custom authorizer. Also MCPEngine added support for idp token validatioin. I've been trying to build a proper cookbook for this with powertools but lack of official SDK support, and seeing lots of sh*tty implementations (that I cant recommend), and the fact that this is sooo new for serverless (protocol changed this week to support non streaming HTTP), leaves me wanting the Powertools treatment :)
Hey @ran-isenberg and @dreamorosi have you seen this from Mike Chambers: https://github.com/mikegc-aws/Lambda-MCP-Server
This might be of interest - I think this could be a good thing to import into Powertools, to be honest.
Hey @ran-isenberg and @dreamorosi have you seen this from Mike Chambers: https://github.com/mikegc-aws/Lambda-MCP-Server
This might be of interest - I think this could be a good thing to import into Powertools, to be honest.
I did, i dont want to offend anyone but it's a nice poc level code. I got it working with powertools. However, i think i'd rather use official mcp python SDK to support http non streaming mode.
Waiting for this: https://github.com/modelcontextprotocol/python-sdk
Hey @walmsles & @ran-isenberg - would you two be available for a quick call in the next week or two?
I'd love to pick your brain on this topic. If we can manage to do it in one call it'd be amazing, but if time zones are a challenge I'm happy to also do one for each.
two weeks from now should be fine, talk to me on discord next week, it's a holiday now :)
Following along to get updates from this thread.
Official was released 2 weeks ago: https://github.com/awslabs/mcp/tree/main/src/mcp-lambda-handler
yeah, seems like they removed the web adapter requirement! I'll built a proper blueprint with CDK around this and share very soon
Thanks a lot @andormarkus, from what I'm seeing the mcp-lambda-handler does not support streaming. Is that correct?
it doesnt. The MCP protocol now supports non streaming HTTP.
@dreamorosi @moise-g @andormarkus I built the template! I used the AWS examples combined them with my own aws lambda handler cookbook and made extra editing... It uses powertools too!
Check it out: https://github.com/ran-isenberg/aws-lambda-mcp-cookbook
@ran-isenberg Fantastic, thanks for sharing!
For one of my use cases, streaming is a hard requirement. My current idea is to go with Fargate (ECS) + Load Balancer. Would that make sense since it looks like Lambda is a no go for streaming?
@ran-isenberg Fantastic, thanks for sharing!
For one of my use cases, streaming is a hard requirement. My current idea is to go with Fargate (ECS) + Load Balancer. Would that make sense since it looks like Lambda is a no go for streaming?
Yes, sounds about right. Here's my prod-ready ( i think so) CDK based repo for Fargate + ELB: https://github.com/ran-isenberg/aws-chatbot-fargate-python
There are definitely some rough edges, but Lambda Web Adapter could be an option here - assuming a few seconds of init are tolerable in this type of workload.
Alternatively, if you aren't too tied to Python, you could switch to Node.js, which does support response streaming with Lambda Function URLs.
@dreamorosi @leandrodamascena Ideally, i'd like pwoertools to own this module: https://github.com/ran-isenberg/aws-lambda-mcp-cookbook/tree/main/service/mcp_lambda_handler - that's the engine, event handler basically. then the experience is like this:
https://github.com/ran-isenberg/aws-lambda-mcp-cookbook/blob/main/service/handlers/mcp.py
Let us talk about it internally - in the next 2 weeks we'll update our roadmap for the back half of the year, so it's a good time to discuss this.
Let us talk about it internally - in the next 2 weeks we'll update our roadmap for the back half of the year, so it's a good time to discuss this.
sure. I think the code is rather simple TBH. The only issue is keeping up with MCP protocol changes. The code is not using the latest changes (missing auth). Also, the code could really use some refactors, moving to classes, reducing complexity etc, but it works!
Just a quick feedback: we've had a few meetings about the roadmap for mid/late 2025 and discussed this issue a bit. While we don't have a decision yet, as we have a few other items to deal with, it's on our radar for a decision soon.
I'll temporarily re-add the triage label so it's picked up on our next planning meeting.
Hi, we have decided to postpone our decision and wait for the New York AWS Summit which will happen in the next 10 days.
Thank you for your patience.
@dreamorosi is there planned timeline for this feature?
Hi @tb102122, no updates at this time.
At the moment we're focused on adding support for new Lambda managed runtimes as well as other items we'll share in the coming weeks.
In the next couple months we'll start creating the roadmap for 2026, so we'll reassess then.