Skip to content

Conversation

@tonyxwz
Copy link

@tonyxwz tonyxwz commented Aug 12, 2025

*Issue #, lifespan is super useful in managing server resources

Description of changes:

just allow BedrockAgentCoreApp to take lifespan and pass the value to starlette.

Agent application might need to start MCP servers which are processes. Since agentcore is a single tenant environment (isolated by session ids), the MCP servers can be launch once in the lifespan, and reused.

@asyncontextmanager
async def mcp_server_manager():
  async with stdio_client("duckduckgo-search") as (read, write):
    async with ClientSession(read, write) as session:
      await session.initialize()
      yield


app = BedrockAgentCoreApp(lifespace=mcp_server_manager)

if __name__ == "__main__":
  app.run()

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@tonyxwz tonyxwz marked this pull request as ready for review August 12, 2025 19:47
@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@255f950). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #51   +/-   ##
=======================================
  Coverage        ?   88.14%           
=======================================
  Files           ?       16           
  Lines           ?     1544           
  Branches        ?      231           
=======================================
  Hits            ?     1361           
  Misses          ?       89           
  Partials        ?       94           
Flag Coverage Δ
unittests 88.14% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@siwachabhi siwachabhi left a comment

Choose a reason for hiding this comment

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

Thanks for raising the PR, could you please add unit tests for the changes

@siwachabhi
Copy link
Contributor

Covering this PR here: #67 added some unit tests

@siwachabhi siwachabhi closed this Sep 5, 2025
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.

3 participants