@aws/agentcore 0.3.0-preview.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/LICENSE +175 -0
  2. package/README.md +147 -0
  3. package/dist/assets/README.md +79 -0
  4. package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +2862 -0
  5. package/dist/assets/__tests__/assets.snapshot.test.ts +139 -0
  6. package/dist/assets/agents/AGENTS.md +102 -0
  7. package/dist/assets/cdk/.prettierrc +8 -0
  8. package/dist/assets/cdk/README.md +14 -0
  9. package/dist/assets/cdk/bin/cdk.ts +50 -0
  10. package/dist/assets/cdk/cdk.json +88 -0
  11. package/dist/assets/cdk/gitignore.template +9 -0
  12. package/dist/assets/cdk/jest.config.js +9 -0
  13. package/dist/assets/cdk/lib/cdk-stack.ts +38 -0
  14. package/dist/assets/cdk/npmignore.template +6 -0
  15. package/dist/assets/cdk/package.json +30 -0
  16. package/dist/assets/cdk/test/cdk.test.ts +16 -0
  17. package/dist/assets/cdk/tsconfig.json +28 -0
  18. package/dist/assets/mcp/python/README.md +27 -0
  19. package/dist/assets/mcp/python/pyproject.toml +22 -0
  20. package/dist/assets/mcp/python/server.py +117 -0
  21. package/dist/assets/mcp/python-lambda/README.md +22 -0
  22. package/dist/assets/mcp/python-lambda/handler.py +144 -0
  23. package/dist/assets/mcp/python-lambda/pyproject.toml +15 -0
  24. package/dist/assets/python/autogen/base/README.md +41 -0
  25. package/dist/assets/python/autogen/base/gitignore.template +40 -0
  26. package/dist/assets/python/autogen/base/main.py +52 -0
  27. package/dist/assets/python/autogen/base/mcp_client/client.py +18 -0
  28. package/dist/assets/python/autogen/base/model/load.py +136 -0
  29. package/dist/assets/python/autogen/base/pyproject.toml +35 -0
  30. package/dist/assets/python/crewai/base/README.md +41 -0
  31. package/dist/assets/python/crewai/base/gitignore.template +40 -0
  32. package/dist/assets/python/crewai/base/main.py +55 -0
  33. package/dist/assets/python/crewai/base/model/load.py +133 -0
  34. package/dist/assets/python/crewai/base/pyproject.toml +32 -0
  35. package/dist/assets/python/googleadk/base/README.md +39 -0
  36. package/dist/assets/python/googleadk/base/gitignore.template +40 -0
  37. package/dist/assets/python/googleadk/base/main.py +84 -0
  38. package/dist/assets/python/googleadk/base/mcp_client/client.py +15 -0
  39. package/dist/assets/python/googleadk/base/model/load.py +41 -0
  40. package/dist/assets/python/googleadk/base/pyproject.toml +21 -0
  41. package/dist/assets/python/langchain_langgraph/base/README.md +41 -0
  42. package/dist/assets/python/langchain_langgraph/base/gitignore.template +40 -0
  43. package/dist/assets/python/langchain_langgraph/base/main.py +51 -0
  44. package/dist/assets/python/langchain_langgraph/base/mcp_client/client.py +19 -0
  45. package/dist/assets/python/langchain_langgraph/base/model/load.py +123 -0
  46. package/dist/assets/python/langchain_langgraph/base/pyproject.toml +37 -0
  47. package/dist/assets/python/openaiagents/base/README.md +39 -0
  48. package/dist/assets/python/openaiagents/base/gitignore.template +40 -0
  49. package/dist/assets/python/openaiagents/base/main.py +56 -0
  50. package/dist/assets/python/openaiagents/base/mcp_client/client.py +14 -0
  51. package/dist/assets/python/openaiagents/base/model/load.py +37 -0
  52. package/dist/assets/python/openaiagents/base/pyproject.toml +20 -0
  53. package/dist/assets/python/strands/base/README.md +41 -0
  54. package/dist/assets/python/strands/base/gitignore.template +41 -0
  55. package/dist/assets/python/strands/base/main.py +76 -0
  56. package/dist/assets/python/strands/base/mcp_client/client.py +12 -0
  57. package/dist/assets/python/strands/base/model/load.py +123 -0
  58. package/dist/assets/python/strands/base/pyproject.toml +23 -0
  59. package/dist/assets/python/strands/capabilities/memory/session.py +39 -0
  60. package/dist/assets/typescript/.gitkeep +0 -0
  61. package/dist/cli/index.mjs +985 -0
  62. package/dist/index.d.ts +9 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +27 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/lib/constants.d.ts +25 -0
  67. package/dist/lib/constants.d.ts.map +1 -0
  68. package/dist/lib/constants.js +49 -0
  69. package/dist/lib/constants.js.map +1 -0
  70. package/dist/lib/errors/config.d.ts +49 -0
  71. package/dist/lib/errors/config.d.ts.map +1 -0
  72. package/dist/lib/errors/config.js +167 -0
  73. package/dist/lib/errors/config.js.map +1 -0
  74. package/dist/lib/errors/index.d.ts +2 -0
  75. package/dist/lib/errors/index.d.ts.map +1 -0
  76. package/dist/lib/errors/index.js +18 -0
  77. package/dist/lib/errors/index.js.map +1 -0
  78. package/dist/lib/index.d.ts +7 -0
  79. package/dist/lib/index.d.ts.map +1 -0
  80. package/dist/lib/index.js +39 -0
  81. package/dist/lib/index.js.map +1 -0
  82. package/dist/lib/packaging/errors.d.ts +16 -0
  83. package/dist/lib/packaging/errors.d.ts.map +1 -0
  84. package/dist/lib/packaging/errors.js +36 -0
  85. package/dist/lib/packaging/errors.js.map +1 -0
  86. package/dist/lib/packaging/helpers.d.ts +54 -0
  87. package/dist/lib/packaging/helpers.d.ts.map +1 -0
  88. package/dist/lib/packaging/helpers.js +461 -0
  89. package/dist/lib/packaging/helpers.js.map +1 -0
  90. package/dist/lib/packaging/index.d.ts +36 -0
  91. package/dist/lib/packaging/index.d.ts.map +1 -0
  92. package/dist/lib/packaging/index.js +89 -0
  93. package/dist/lib/packaging/index.js.map +1 -0
  94. package/dist/lib/packaging/node.d.ts +17 -0
  95. package/dist/lib/packaging/node.d.ts.map +1 -0
  96. package/dist/lib/packaging/node.js +108 -0
  97. package/dist/lib/packaging/node.js.map +1 -0
  98. package/dist/lib/packaging/python.d.ts +17 -0
  99. package/dist/lib/packaging/python.d.ts.map +1 -0
  100. package/dist/lib/packaging/python.js +162 -0
  101. package/dist/lib/packaging/python.js.map +1 -0
  102. package/dist/lib/packaging/types/index.d.ts +2 -0
  103. package/dist/lib/packaging/types/index.d.ts.map +1 -0
  104. package/dist/lib/packaging/types/index.js +3 -0
  105. package/dist/lib/packaging/types/index.js.map +1 -0
  106. package/dist/lib/packaging/types/packaging.d.ts +57 -0
  107. package/dist/lib/packaging/types/packaging.d.ts.map +1 -0
  108. package/dist/lib/packaging/types/packaging.js +3 -0
  109. package/dist/lib/packaging/types/packaging.js.map +1 -0
  110. package/dist/lib/packaging/uv.d.ts +7 -0
  111. package/dist/lib/packaging/uv.d.ts.map +1 -0
  112. package/dist/lib/packaging/uv.js +40 -0
  113. package/dist/lib/packaging/uv.js.map +1 -0
  114. package/dist/lib/schemas/io/config-io.d.ts +106 -0
  115. package/dist/lib/schemas/io/config-io.d.ts.map +1 -0
  116. package/dist/lib/schemas/io/config-io.js +293 -0
  117. package/dist/lib/schemas/io/config-io.js.map +1 -0
  118. package/dist/lib/schemas/io/index.d.ts +3 -0
  119. package/dist/lib/schemas/io/index.d.ts.map +1 -0
  120. package/dist/lib/schemas/io/index.js +17 -0
  121. package/dist/lib/schemas/io/index.js.map +1 -0
  122. package/dist/lib/schemas/io/path-resolver.d.ts +112 -0
  123. package/dist/lib/schemas/io/path-resolver.d.ts.map +1 -0
  124. package/dist/lib/schemas/io/path-resolver.js +195 -0
  125. package/dist/lib/schemas/io/path-resolver.js.map +1 -0
  126. package/dist/lib/utils/aws-account.d.ts +7 -0
  127. package/dist/lib/utils/aws-account.d.ts.map +1 -0
  128. package/dist/lib/utils/aws-account.js +24 -0
  129. package/dist/lib/utils/aws-account.js.map +1 -0
  130. package/dist/lib/utils/credentials.d.ts +86 -0
  131. package/dist/lib/utils/credentials.d.ts.map +1 -0
  132. package/dist/lib/utils/credentials.js +153 -0
  133. package/dist/lib/utils/credentials.js.map +1 -0
  134. package/dist/lib/utils/env.d.ts +22 -0
  135. package/dist/lib/utils/env.d.ts.map +1 -0
  136. package/dist/lib/utils/env.js +65 -0
  137. package/dist/lib/utils/env.js.map +1 -0
  138. package/dist/lib/utils/index.d.ts +7 -0
  139. package/dist/lib/utils/index.d.ts.map +1 -0
  140. package/dist/lib/utils/index.js +23 -0
  141. package/dist/lib/utils/index.js.map +1 -0
  142. package/dist/lib/utils/platform.d.ts +63 -0
  143. package/dist/lib/utils/platform.d.ts.map +1 -0
  144. package/dist/lib/utils/platform.js +88 -0
  145. package/dist/lib/utils/platform.js.map +1 -0
  146. package/dist/lib/utils/subprocess.d.ts +29 -0
  147. package/dist/lib/utils/subprocess.d.ts.map +1 -0
  148. package/dist/lib/utils/subprocess.js +94 -0
  149. package/dist/lib/utils/subprocess.js.map +1 -0
  150. package/dist/lib/utils/zod.d.ts +14 -0
  151. package/dist/lib/utils/zod.d.ts.map +1 -0
  152. package/dist/lib/utils/zod.js +32 -0
  153. package/dist/lib/utils/zod.js.map +1 -0
  154. package/dist/schema/constants.d.ts +82 -0
  155. package/dist/schema/constants.d.ts.map +1 -0
  156. package/dist/schema/constants.js +117 -0
  157. package/dist/schema/constants.js.map +1 -0
  158. package/dist/schema/index.d.ts +4 -0
  159. package/dist/schema/index.d.ts.map +1 -0
  160. package/dist/schema/index.js +21 -0
  161. package/dist/schema/index.js.map +1 -0
  162. package/dist/schema/schemas/agent-env.d.ts +75 -0
  163. package/dist/schema/schemas/agent-env.d.ts.map +1 -0
  164. package/dist/schema/schemas/agent-env.js +84 -0
  165. package/dist/schema/schemas/agent-env.js.map +1 -0
  166. package/dist/schema/schemas/agentcore-project.d.ts +88 -0
  167. package/dist/schema/schemas/agentcore-project.d.ts.map +1 -0
  168. package/dist/schema/schemas/agentcore-project.js +83 -0
  169. package/dist/schema/schemas/agentcore-project.js.map +1 -0
  170. package/dist/schema/schemas/aws-targets.d.ts +50 -0
  171. package/dist/schema/schemas/aws-targets.d.ts.map +1 -0
  172. package/dist/schema/schemas/aws-targets.js +49 -0
  173. package/dist/schema/schemas/aws-targets.js.map +1 -0
  174. package/dist/schema/schemas/deployed-state.d.ts +260 -0
  175. package/dist/schema/schemas/deployed-state.d.ts.map +1 -0
  176. package/dist/schema/schemas/deployed-state.js +100 -0
  177. package/dist/schema/schemas/deployed-state.js.map +1 -0
  178. package/dist/schema/schemas/index.d.ts +8 -0
  179. package/dist/schema/schemas/index.d.ts.map +1 -0
  180. package/dist/schema/schemas/index.js +25 -0
  181. package/dist/schema/schemas/index.js.map +1 -0
  182. package/dist/schema/schemas/mcp-defs.d.ts +52 -0
  183. package/dist/schema/schemas/mcp-defs.d.ts.map +1 -0
  184. package/dist/schema/schemas/mcp-defs.js +50 -0
  185. package/dist/schema/schemas/mcp-defs.js.map +1 -0
  186. package/dist/schema/schemas/mcp.d.ts +659 -0
  187. package/dist/schema/schemas/mcp.d.ts.map +1 -0
  188. package/dist/schema/schemas/mcp.js +283 -0
  189. package/dist/schema/schemas/mcp.js.map +1 -0
  190. package/dist/schema/schemas/primitives/index.d.ts +3 -0
  191. package/dist/schema/schemas/primitives/index.d.ts.map +1 -0
  192. package/dist/schema/schemas/primitives/index.js +9 -0
  193. package/dist/schema/schemas/primitives/index.js.map +1 -0
  194. package/dist/schema/schemas/primitives/memory.d.ts +42 -0
  195. package/dist/schema/schemas/primitives/memory.d.ts.map +1 -0
  196. package/dist/schema/schemas/primitives/memory.js +50 -0
  197. package/dist/schema/schemas/primitives/memory.js.map +1 -0
  198. package/dist/schema/schemas/zod-util.d.ts +10 -0
  199. package/dist/schema/schemas/zod-util.d.ts.map +1 -0
  200. package/dist/schema/schemas/zod-util.js +23 -0
  201. package/dist/schema/schemas/zod-util.js.map +1 -0
  202. package/dist/schema/types/index.d.ts +2 -0
  203. package/dist/schema/types/index.d.ts.map +1 -0
  204. package/dist/schema/types/index.js +18 -0
  205. package/dist/schema/types/index.js.map +1 -0
  206. package/dist/schema/types/path.d.ts +27 -0
  207. package/dist/schema/types/path.d.ts.map +1 -0
  208. package/dist/schema/types/path.js +13 -0
  209. package/dist/schema/types/path.js.map +1 -0
  210. package/package.json +111 -0
  211. package/scripts/bump-version.ts +442 -0
  212. package/scripts/check-old-cli.mjs +26 -0
  213. package/scripts/copy-assets.mjs +50 -0
@@ -0,0 +1,117 @@
1
+ """
2
+ MCP Server demonstrating HTTP tool patterns.
3
+
4
+ This template shows:
5
+ - Async HTTP boundaries with proper error handling
6
+ - Retry logic and partial failure
7
+ - Response parsing and validation
8
+
9
+ Run with: uv run server.py
10
+ """
11
+
12
+ import logging
13
+ from typing import Any
14
+
15
+ import httpx
16
+ from mcp.server.fastmcp import FastMCP
17
+
18
+ logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s")
19
+ logger = logging.getLogger(__name__)
20
+
21
+ mcp = FastMCP("tools")
22
+
23
+ HTTP_TIMEOUT = 10.0
24
+ MAX_RETRIES = 2
25
+
26
+
27
+ async def fetch_json(url: str, headers: dict[str, str] | None = None) -> dict[str, Any] | None:
28
+ """Make an HTTP GET request with retry logic."""
29
+ async with httpx.AsyncClient() as client:
30
+ for attempt in range(MAX_RETRIES):
31
+ try:
32
+ response = await client.get(url, headers=headers, timeout=HTTP_TIMEOUT)
33
+ response.raise_for_status()
34
+ return response.json()
35
+ except httpx.TimeoutException:
36
+ logger.warning(f"Timeout on attempt {attempt + 1} for {url}")
37
+ except httpx.HTTPStatusError as e:
38
+ logger.error(f"HTTP {e.response.status_code} for {url}")
39
+ return None
40
+ except httpx.RequestError as e:
41
+ logger.error(f"Request failed: {e}")
42
+ return None
43
+ return None
44
+
45
+
46
+ @mcp.tool()
47
+ async def lookup_ip(ip_address: str) -> str:
48
+ """Look up geolocation and network info for an IP address.
49
+
50
+ Args:
51
+ ip_address: IPv4 or IPv6 address to look up
52
+ """
53
+ data = await fetch_json(f"http://ip-api.com/json/{ip_address}")
54
+
55
+ if not data:
56
+ return f"Failed to look up IP: {ip_address}"
57
+
58
+ if data.get("status") == "fail":
59
+ return f"Lookup failed: {data.get('message', 'unknown error')}"
60
+
61
+ return (
62
+ f"IP: {data['query']}\n"
63
+ f"Location: {data['city']}, {data['regionName']}, {data['country']}\n"
64
+ f"ISP: {data['isp']}\n"
65
+ f"Organization: {data['org']}\n"
66
+ f"Timezone: {data['timezone']}"
67
+ )
68
+
69
+
70
+ @mcp.tool()
71
+ async def get_random_user() -> str:
72
+ """Generate a random user profile for testing or mock data."""
73
+ data = await fetch_json("https://randomuser.me/api/")
74
+
75
+ if not data or "results" not in data:
76
+ return "Failed to generate random user."
77
+
78
+ user = data["results"][0]
79
+ name = user["name"]
80
+ location = user["location"]
81
+
82
+ return (
83
+ f"Name: {name['first']} {name['last']}\n"
84
+ f"Email: {user['email']}\n"
85
+ f"Location: {location['city']}, {location['country']}\n"
86
+ f"Phone: {user['phone']}"
87
+ )
88
+
89
+
90
+ @mcp.tool()
91
+ async def fetch_post(post_id: int) -> str:
92
+ """Fetch a post by ID from JSONPlaceholder API.
93
+
94
+ Args:
95
+ post_id: The post ID (1-100)
96
+ """
97
+ if not 1 <= post_id <= 100:
98
+ return "Post ID must be between 1 and 100."
99
+
100
+ data = await fetch_json(f"https://jsonplaceholder.typicode.com/posts/{post_id}")
101
+
102
+ if not data:
103
+ return f"Failed to fetch post {post_id}."
104
+
105
+ return (
106
+ f"Post #{data['id']}\n"
107
+ f"Title: {data['title']}\n\n"
108
+ f"{data['body']}"
109
+ )
110
+
111
+
112
+ def main():
113
+ mcp.run(transport="stdio")
114
+
115
+
116
+ if __name__ == "__main__":
117
+ main()
@@ -0,0 +1,22 @@
1
+ # {{ Name }}
2
+
3
+ Lambda-based tools for AgentCore Gateway.
4
+
5
+ ## Tools
6
+
7
+ - `lookup_ip` - Look up geolocation for an IP address
8
+ - `get_random_user` - Generate random user profile
9
+ - `fetch_post` - Fetch a post by ID
10
+
11
+ ## Gateway Integration
12
+
13
+ Tools are invoked via AgentCore Gateway. The tool name is passed in:
14
+ `context.client_context.custom["bedrockAgentCoreToolName"]`
15
+
16
+ Format: `{target_name}___{tool_name}`
17
+
18
+ ## Adding New Tools
19
+
20
+ 1. Define the tool function with the `@tool("tool_name")` decorator
21
+ 2. Add the tool definition to `mcp-defs.json` in your agentcore project
22
+ 3. The tool will be automatically routed by the handler
@@ -0,0 +1,144 @@
1
+ """
2
+ Lambda handler for AgentCore Gateway tools.
3
+
4
+ This template mirrors the FastMCP server tools but runs as a Lambda function
5
+ behind an AgentCore Gateway.
6
+
7
+ Tool routing uses bedrockAgentCoreToolName from client context:
8
+ Format: {target_name}___{tool_name}
9
+ """
10
+ import json
11
+ import logging
12
+ import urllib.request
13
+ import urllib.error
14
+ from typing import Any, Dict, Optional
15
+
16
+ logger = logging.getLogger()
17
+ logger.setLevel(logging.INFO)
18
+
19
+ HTTP_TIMEOUT = 10
20
+ TOOLS = {}
21
+
22
+
23
+ def tool(name: str):
24
+ """Decorator to register a tool handler."""
25
+ def decorator(func):
26
+ TOOLS[name] = func
27
+ return func
28
+ return decorator
29
+
30
+
31
+ def lambda_handler(event: Dict[str, Any], context) -> Dict[str, Any]:
32
+ """Route incoming gateway requests to the appropriate tool."""
33
+ try:
34
+ extended_name = context.client_context.custom.get("bedrockAgentCoreToolName", "")
35
+ tool_name = None
36
+
37
+ if "___" in extended_name:
38
+ tool_name = extended_name.split("___", 1)[1]
39
+
40
+ if not tool_name:
41
+ return _response(400, {"error": "Missing tool name in bedrockAgentCoreToolName"})
42
+
43
+ handler = TOOLS.get(tool_name)
44
+ if not handler:
45
+ return _response(400, {"error": f"Unknown tool: {tool_name}"})
46
+
47
+ result = handler(event)
48
+ return _response(200, {"result": result})
49
+
50
+ except Exception as e:
51
+ logger.exception("Tool execution failed")
52
+ return _response(500, {"error": str(e)})
53
+
54
+
55
+ def _response(status_code: int, body: Dict[str, Any]) -> Dict[str, Any]:
56
+ """Consistent JSON response wrapper."""
57
+ return {"statusCode": status_code, "body": json.dumps(body)}
58
+
59
+
60
+ def _fetch_json(url: str) -> Optional[Dict[str, Any]]:
61
+ """Fetch JSON from URL with error handling."""
62
+ try:
63
+ req = urllib.request.Request(url, headers={"User-Agent": "AgentCore-Tool/1.0"})
64
+ with urllib.request.urlopen(req, timeout=HTTP_TIMEOUT) as resp:
65
+ return json.loads(resp.read().decode())
66
+ except (urllib.error.URLError, json.JSONDecodeError) as e:
67
+ logger.warning(f"Failed to fetch {url}: {e}")
68
+ return None
69
+
70
+
71
+ @tool("{{Name}}_lookup_ip")
72
+ def lookup_ip(event: Dict[str, Any]) -> str:
73
+ """Look up geolocation and network info for an IP address.
74
+
75
+ Args:
76
+ ip_address: IPv4 or IPv6 address to look up
77
+ """
78
+ ip_address = event.get("ip_address", "")
79
+ if not ip_address:
80
+ return "Missing required parameter: ip_address"
81
+
82
+ data = _fetch_json(f"http://ip-api.com/json/{ip_address}")
83
+ if not data:
84
+ return f"Failed to look up IP: {ip_address}"
85
+
86
+ if data.get("status") == "fail":
87
+ return f"Lookup failed: {data.get('message', 'unknown error')}"
88
+
89
+ return (
90
+ f"IP: {data['query']}\n"
91
+ f"Location: {data['city']}, {data['regionName']}, {data['country']}\n"
92
+ f"ISP: {data['isp']}\n"
93
+ f"Organization: {data['org']}\n"
94
+ f"Timezone: {data['timezone']}"
95
+ )
96
+
97
+
98
+ @tool("{{Name}}_get_random_user")
99
+ def get_random_user(event: Dict[str, Any]) -> str:
100
+ """Generate a random user profile for testing or mock data."""
101
+ data = _fetch_json("https://randomuser.me/api/")
102
+ if not data or "results" not in data:
103
+ return "Failed to generate random user."
104
+
105
+ user = data["results"][0]
106
+ name = user["name"]
107
+ location = user["location"]
108
+
109
+ return (
110
+ f"Name: {name['first']} {name['last']}\n"
111
+ f"Email: {user['email']}\n"
112
+ f"Location: {location['city']}, {location['country']}\n"
113
+ f"Phone: {user['phone']}"
114
+ )
115
+
116
+
117
+ @tool("{{Name}}_fetch_post")
118
+ def fetch_post(event: Dict[str, Any]) -> str:
119
+ """Fetch a post by ID from JSONPlaceholder API.
120
+
121
+ Args:
122
+ post_id: The post ID (1-100)
123
+ """
124
+ post_id = event.get("post_id")
125
+ if post_id is None:
126
+ return "Missing required parameter: post_id"
127
+
128
+ try:
129
+ post_id = int(post_id)
130
+ except (TypeError, ValueError):
131
+ return "post_id must be an integer"
132
+
133
+ if not 1 <= post_id <= 100:
134
+ return "Post ID must be between 1 and 100."
135
+
136
+ data = _fetch_json(f"https://jsonplaceholder.typicode.com/posts/{post_id}")
137
+ if not data:
138
+ return f"Failed to fetch post {post_id}."
139
+
140
+ return (
141
+ f"Post #{data['id']}\n"
142
+ f"Title: {data['title']}\n\n"
143
+ f"{data['body']}"
144
+ )
@@ -0,0 +1,15 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "{{ name }}"
7
+ version = "0.1.0"
8
+ description = "Lambda tools for AgentCore Gateway"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ # No external dependencies - uses stdlib only
12
+ dependencies = []
13
+
14
+ [tool.hatch.build.targets.wheel]
15
+ packages = ["."]
@@ -0,0 +1,41 @@
1
+ This is a project generated by the agentcore create CLI tool!
2
+
3
+ # Layout
4
+
5
+ There is one directory with generated application code, `src/` . At the root, there is a `.gitignore` file, a
6
+ `.agentcore` folder which represents the configurations and state associated with this project. Other `agentcore`
7
+ commands like `deploy`, `dev`, and `invoke` rely on the configuration stored here.
8
+
9
+ ## src/
10
+
11
+ The main entrypoint to your app is defined in `src/main.py`. Using the AgentCore SDK `@app.entrypoint` decorator, this
12
+ file defines a Starlette ASGI app with the AutoGen framework running within.
13
+
14
+ `src/model/load.py` instantiates your chosen model provider.
15
+
16
+ ## Environment Variables
17
+
18
+ | Variable | Required | Description |
19
+ | ------------------------------ | --------------- | ---------------------------------------------------------------- |
20
+ | `AGENTCORE_IDENTITY_OPENAI` | Yes (OpenAI) | OpenAI API key (local) or Identity provider name (deployed) |
21
+ | `AGENTCORE_IDENTITY_ANTHROPIC` | Yes (Anthropic) | Anthropic API key (local) or Identity provider name (deployed) |
22
+ | `AGENTCORE_IDENTITY_GEMINI` | Yes (Gemini) | Gemini API key (local) or Identity provider name (deployed) |
23
+ | `LOCAL_DEV` | No | Set to `1` to use `agentcore/.env` instead of AgentCore Identity |
24
+
25
+ # Developing locally
26
+
27
+ If installation was successful, a virtual environment is already created with dependencies installed.
28
+
29
+ Run `source .venv/bin/activate` before developing.
30
+
31
+ `agentcore dev` will start a local server on 0.0.0.0:8080.
32
+
33
+ In a new terminal, you can invoke that server with:
34
+
35
+ `agentcore invoke --dev "What can you do"`
36
+
37
+ # Deployment
38
+
39
+ After providing credentials, `agentcore deploy` will deploy your project into Amazon Bedrock AgentCore.
40
+
41
+ Use `agentcore invoke` to invoke your deployed agent.
@@ -0,0 +1,40 @@
1
+ # Environment variables
2
+ .env
3
+
4
+ # Python
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+ *.so
9
+ .Python
10
+ build/
11
+ develop-eggs/
12
+ dist/
13
+ downloads/
14
+ eggs/
15
+ .eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ wheels/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+
26
+ # Virtual environments
27
+ venv/
28
+ ENV/
29
+ env/
30
+
31
+ # IDE
32
+ .vscode/
33
+ .idea/
34
+ *.swp
35
+ *.swo
36
+ *~
37
+
38
+ # OS
39
+ .DS_Store
40
+ Thumbs.db
@@ -0,0 +1,52 @@
1
+ import os
2
+ from autogen_agentchat.agents import AssistantAgent
3
+ from autogen_core.tools import FunctionTool
4
+ from bedrock_agentcore.runtime import BedrockAgentCoreApp
5
+ from model.load import load_model
6
+ from mcp_client.client import get_streamable_http_mcp_tools
7
+
8
+ app = BedrockAgentCoreApp()
9
+ log = app.logger
10
+
11
+
12
+ # Define a simple function tool
13
+ def add_numbers(a: int, b: int) -> int:
14
+ """Return the sum of two numbers"""
15
+ return a + b
16
+
17
+
18
+ add_numbers_tool = FunctionTool(
19
+ add_numbers, description="Return the sum of two numbers"
20
+ )
21
+
22
+ # Define a collection of tools used by the model
23
+ tools = [add_numbers_tool]
24
+
25
+
26
+ @app.entrypoint
27
+ async def invoke(payload, context):
28
+ log.info("Invoking Agent.....")
29
+
30
+ # Get MCP Tools
31
+ mcp_tools = await get_streamable_http_mcp_tools()
32
+
33
+ # Define an AssistantAgent with the model and tools
34
+ agent = AssistantAgent(
35
+ name="{{ name }}",
36
+ model_client=load_model(),
37
+ tools=tools + mcp_tools,
38
+ system_message="You are a helpful assistant. Use tools when appropriate.",
39
+ )
40
+
41
+ # Process the user prompt
42
+ prompt = payload.get("prompt", "What can you help me with?")
43
+
44
+ # Run the agent
45
+ result = await agent.run(task=prompt)
46
+
47
+ # Return result
48
+ return {"result": result.messages[-1].content}
49
+
50
+
51
+ if __name__ == "__main__":
52
+ app.run()
@@ -0,0 +1,18 @@
1
+ from typing import List
2
+ from autogen_ext.tools.mcp import (
3
+ StreamableHttpMcpToolAdapter,
4
+ StreamableHttpServerParams,
5
+ mcp_server_tools,
6
+ )
7
+
8
+ # ExaAI provides information about code through web searches, crawling and code context searches through their platform. Requires no authentication
9
+ EXAMPLE_MCP_ENDPOINT = "https://mcp.exa.ai/mcp"
10
+
11
+
12
+ async def get_streamable_http_mcp_tools() -> List[StreamableHttpMcpToolAdapter]:
13
+ """
14
+ Returns MCP Tools compatible with AutoGen.
15
+ """
16
+ # to use an MCP server that supports bearer authentication, add headers={"Authorization": f"Bearer {access_token}"}
17
+ server_params = StreamableHttpServerParams(url=EXAMPLE_MCP_ENDPOINT)
18
+ return await mcp_server_tools(server_params)
@@ -0,0 +1,136 @@
1
+ {{#if (eq modelProvider "Bedrock")}}
2
+ import os
3
+ from autogen_ext.models.anthropic import AnthropicBedrockChatCompletionClient
4
+ from autogen_core.models import ModelInfo, ModelFamily
5
+
6
+ # Uses global inference profile for Claude Sonnet 4.5
7
+ # https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html
8
+ MODEL_ID = "global.anthropic.claude-sonnet-4-5-20250929-v1:0"
9
+
10
+
11
+ def load_model() -> AnthropicBedrockChatCompletionClient:
12
+ """Get Bedrock model client using IAM credentials."""
13
+ return AnthropicBedrockChatCompletionClient(
14
+ model=MODEL_ID,
15
+ model_info=ModelInfo(
16
+ vision=False,
17
+ function_calling=True,
18
+ json_output=False,
19
+ family=ModelFamily.CLAUDE_4_SONNET,
20
+ structured_output=True
21
+ ),
22
+ bedrock_info={"aws_region": os.environ.get("AWS_REGION", "us-east-1")}
23
+ )
24
+ {{/if}}
25
+ {{#if (eq modelProvider "Anthropic")}}
26
+ import os
27
+ from autogen_ext.models.anthropic import AnthropicChatCompletionClient
28
+ from bedrock_agentcore.identity.auth import requires_api_key
29
+
30
+ IDENTITY_PROVIDER_NAME = "{{identityProviders.[0].name}}"
31
+ IDENTITY_ENV_VAR = "{{identityProviders.[0].envVarName}}"
32
+
33
+
34
+ @requires_api_key(provider_name=IDENTITY_PROVIDER_NAME)
35
+ def _agentcore_identity_api_key_provider(api_key: str) -> str:
36
+ """Fetch API key from AgentCore Identity."""
37
+ return api_key
38
+
39
+
40
+ def _get_api_key() -> str:
41
+ """
42
+ Uses AgentCore Identity for API key management in deployed environments.
43
+ For local development, run via 'agentcore dev' which loads agentcore/.env.
44
+ """
45
+ if os.getenv("LOCAL_DEV") == "1":
46
+ api_key = os.getenv(IDENTITY_ENV_VAR)
47
+ if not api_key:
48
+ raise RuntimeError(
49
+ f"{IDENTITY_ENV_VAR} not found. Add {IDENTITY_ENV_VAR}=your-key to .env.local"
50
+ )
51
+ return api_key
52
+ return _agentcore_identity_api_key_provider()
53
+
54
+
55
+ def load_model() -> AnthropicChatCompletionClient:
56
+ """Get authenticated Anthropic model client."""
57
+ return AnthropicChatCompletionClient(
58
+ model="claude-sonnet-4-5-20250929",
59
+ api_key=_get_api_key()
60
+ )
61
+ {{/if}}
62
+ {{#if (eq modelProvider "OpenAI")}}
63
+ import os
64
+ from autogen_ext.models.openai import OpenAIChatCompletionClient
65
+ from bedrock_agentcore.identity.auth import requires_api_key
66
+
67
+ IDENTITY_PROVIDER_NAME = "{{identityProviders.[0].name}}"
68
+ IDENTITY_ENV_VAR = "{{identityProviders.[0].envVarName}}"
69
+
70
+
71
+ @requires_api_key(provider_name=IDENTITY_PROVIDER_NAME)
72
+ def _agentcore_identity_api_key_provider(api_key: str) -> str:
73
+ """Fetch API key from AgentCore Identity."""
74
+ return api_key
75
+
76
+
77
+ def _get_api_key() -> str:
78
+ """
79
+ Uses AgentCore Identity for API key management in deployed environments.
80
+ For local development, run via 'agentcore dev' which loads agentcore/.env.
81
+ """
82
+ if os.getenv("LOCAL_DEV") == "1":
83
+ api_key = os.getenv(IDENTITY_ENV_VAR)
84
+ if not api_key:
85
+ raise RuntimeError(
86
+ f"{IDENTITY_ENV_VAR} not found. Add {IDENTITY_ENV_VAR}=your-key to .env.local"
87
+ )
88
+ return api_key
89
+ return _agentcore_identity_api_key_provider()
90
+
91
+
92
+ def load_model() -> OpenAIChatCompletionClient:
93
+ """Get authenticated OpenAI model client."""
94
+ return OpenAIChatCompletionClient(
95
+ model="gpt-4o",
96
+ api_key=_get_api_key()
97
+ )
98
+ {{/if}}
99
+ {{#if (eq modelProvider "Gemini")}}
100
+ import os
101
+ from autogen_ext.models.openai import OpenAIChatCompletionClient
102
+ from bedrock_agentcore.identity.auth import requires_api_key
103
+
104
+ IDENTITY_PROVIDER_NAME = "{{identityProviders.[0].name}}"
105
+ IDENTITY_ENV_VAR = "{{identityProviders.[0].envVarName}}"
106
+
107
+
108
+ @requires_api_key(provider_name=IDENTITY_PROVIDER_NAME)
109
+ def _agentcore_identity_api_key_provider(api_key: str) -> str:
110
+ """Fetch API key from AgentCore Identity."""
111
+ return api_key
112
+
113
+
114
+ def _get_api_key() -> str:
115
+ """
116
+ Uses AgentCore Identity for API key management in deployed environments.
117
+ For local development, run via 'agentcore dev' which loads agentcore/.env.
118
+ """
119
+ if os.getenv("LOCAL_DEV") == "1":
120
+ api_key = os.getenv(IDENTITY_ENV_VAR)
121
+ if not api_key:
122
+ raise RuntimeError(
123
+ f"{IDENTITY_ENV_VAR} not found. Add {IDENTITY_ENV_VAR}=your-key to .env.local"
124
+ )
125
+ return api_key
126
+ return _agentcore_identity_api_key_provider()
127
+
128
+
129
+ def load_model() -> OpenAIChatCompletionClient:
130
+ """Get authenticated Gemini model client via OpenAI-compatible API."""
131
+ return OpenAIChatCompletionClient(
132
+ model="gemini-2.0-flash",
133
+ api_key=_get_api_key(),
134
+ base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
135
+ )
136
+ {{/if}}
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "{{ name }}"
7
+ version = "0.1.0"
8
+ description = "AgentCore Runtime Application using AutoGen SDK"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = [
12
+ "autogen-agentchat >= 0.7.5",
13
+ "autogen-ext[mcp] >= 0.7.5",
14
+ "opentelemetry-distro",
15
+ "opentelemetry-exporter-otlp",
16
+ "bedrock-agentcore >= 1.0.3",
17
+ "botocore[crt] >= 1.35.0",
18
+ "python-dotenv >= 1.0.1",
19
+ "tiktoken",
20
+ {{#if (eq modelProvider "Bedrock")}}
21
+ "autogen-ext[anthropic] >= 0.7.5",
22
+ {{/if}}
23
+ {{#if (eq modelProvider "Anthropic")}}
24
+ "autogen-ext[anthropic] >= 0.7.5",
25
+ {{/if}}
26
+ {{#if (eq modelProvider "OpenAI")}}
27
+ "autogen-ext[openai] >= 0.7.5",
28
+ {{/if}}
29
+ {{#if (eq modelProvider "Gemini")}}
30
+ "autogen-ext[openai] >= 0.7.5",
31
+ {{/if}}
32
+ ]
33
+
34
+ [tool.hatch.build.targets.wheel]
35
+ packages = ["."]
@@ -0,0 +1,41 @@
1
+ This is a project generated by the agentcore create CLI tool!
2
+
3
+ # Layout
4
+
5
+ There is one directory with generated application code, `src/` . At the root, there is a `.gitignore` file, a
6
+ `.agentcore` folder which represents the configurations and state associated with this project. Other `agentcore`
7
+ commands like `deploy`, `dev`, and `invoke` rely on the configuration stored here.
8
+
9
+ ## src/
10
+
11
+ The main entrypoint to your app is defined in `src/main.py`. Using the AgentCore SDK `@app.entrypoint` decorator, this
12
+ file defines a Starlette ASGI app with the CrewAI framework running within.
13
+
14
+ `src/model/load.py` instantiates your chosen model provider.
15
+
16
+ ## Environment Variables
17
+
18
+ | Variable | Required | Description |
19
+ | ------------------------------ | --------------- | ---------------------------------------------------------------- |
20
+ | `AGENTCORE_IDENTITY_OPENAI` | Yes (OpenAI) | OpenAI API key (local) or Identity provider name (deployed) |
21
+ | `AGENTCORE_IDENTITY_ANTHROPIC` | Yes (Anthropic) | Anthropic API key (local) or Identity provider name (deployed) |
22
+ | `AGENTCORE_IDENTITY_GEMINI` | Yes (Gemini) | Gemini API key (local) or Identity provider name (deployed) |
23
+ | `LOCAL_DEV` | No | Set to `1` to use `agentcore/.env` instead of AgentCore Identity |
24
+
25
+ # Developing locally
26
+
27
+ If installation was successful, a virtual environment is already created with dependencies installed.
28
+
29
+ Run `source .venv/bin/activate` before developing.
30
+
31
+ `agentcore dev` will start a local server on 0.0.0.0:8080.
32
+
33
+ In a new terminal, you can invoke that server with:
34
+
35
+ `agentcore invoke --dev "What can you do"`
36
+
37
+ # Deployment
38
+
39
+ After providing credentials, `agentcore deploy` will deploy your project into Amazon Bedrock AgentCore.
40
+
41
+ Use `agentcore invoke` to invoke your deployed agent.