awslabs.lambda-tool-mcp-server 2.0.0__py3-none-any.whl
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.
- awslabs/__init__.py +2 -0
- awslabs/lambda_tool_mcp_server/__init__.py +3 -0
- awslabs/lambda_tool_mcp_server/server.py +308 -0
- awslabs_lambda_tool_mcp_server-2.0.0.dist-info/METADATA +191 -0
- awslabs_lambda_tool_mcp_server-2.0.0.dist-info/RECORD +9 -0
- awslabs_lambda_tool_mcp_server-2.0.0.dist-info/WHEEL +4 -0
- awslabs_lambda_tool_mcp_server-2.0.0.dist-info/entry_points.txt +2 -0
- awslabs_lambda_tool_mcp_server-2.0.0.dist-info/licenses/LICENSE +175 -0
- awslabs_lambda_tool_mcp_server-2.0.0.dist-info/licenses/NOTICE +2 -0
awslabs/__init__.py
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"""awslabs lambda MCP Server implementation."""
|
|
2
|
+
|
|
3
|
+
import boto3
|
|
4
|
+
import json
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
from mcp.server.fastmcp import Context, FastMCP
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Set up logging
|
|
13
|
+
logging.basicConfig(level=logging.INFO)
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
AWS_PROFILE = os.environ.get('AWS_PROFILE', 'default')
|
|
17
|
+
logger.info(f'AWS_PROFILE: {AWS_PROFILE}')
|
|
18
|
+
|
|
19
|
+
AWS_REGION = os.environ.get('AWS_REGION', 'us-east-1')
|
|
20
|
+
logger.info(f'AWS_REGION: {AWS_REGION}')
|
|
21
|
+
|
|
22
|
+
FUNCTION_PREFIX = os.environ.get('FUNCTION_PREFIX', '')
|
|
23
|
+
logger.info(f'FUNCTION_PREFIX: {FUNCTION_PREFIX}')
|
|
24
|
+
|
|
25
|
+
FUNCTION_LIST = [
|
|
26
|
+
function_name.strip()
|
|
27
|
+
for function_name in os.environ.get('FUNCTION_LIST', '').split(',')
|
|
28
|
+
if function_name.strip()
|
|
29
|
+
]
|
|
30
|
+
logger.info(f'FUNCTION_LIST: {FUNCTION_LIST}')
|
|
31
|
+
|
|
32
|
+
FUNCTION_TAG_KEY = os.environ.get('FUNCTION_TAG_KEY', '')
|
|
33
|
+
logger.info(f'FUNCTION_TAG_KEY: {FUNCTION_TAG_KEY}')
|
|
34
|
+
|
|
35
|
+
FUNCTION_TAG_VALUE = os.environ.get('FUNCTION_TAG_VALUE', '')
|
|
36
|
+
logger.info(f'FUNCTION_TAG_VALUE: {FUNCTION_TAG_VALUE}')
|
|
37
|
+
|
|
38
|
+
FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY = os.environ.get('FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY')
|
|
39
|
+
logger.info(f'FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY: {FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY}')
|
|
40
|
+
|
|
41
|
+
# Initialize AWS clients
|
|
42
|
+
session = boto3.Session(profile_name=AWS_PROFILE, region_name=AWS_REGION)
|
|
43
|
+
lambda_client = session.client('lambda')
|
|
44
|
+
schemas_client = session.client('schemas')
|
|
45
|
+
|
|
46
|
+
mcp = FastMCP(
|
|
47
|
+
'awslabs.lambda-tool-mcp-server',
|
|
48
|
+
instructions="""Use AWS Lambda functions to improve your answers.
|
|
49
|
+
These Lambda functions give you additional capabilities and access to AWS services and resources in an AWS account.""",
|
|
50
|
+
dependencies=['pydantic', 'boto3'],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def validate_function_name(function_name: str) -> bool:
|
|
55
|
+
"""Validate that the function name is valid and can be called."""
|
|
56
|
+
# If both prefix and list are empty, consider all functions valid
|
|
57
|
+
if not FUNCTION_PREFIX and not FUNCTION_LIST:
|
|
58
|
+
return True
|
|
59
|
+
|
|
60
|
+
# Otherwise, check if the function name matches the prefix or is in the list
|
|
61
|
+
return (FUNCTION_PREFIX and function_name.startswith(FUNCTION_PREFIX)) or (
|
|
62
|
+
function_name in FUNCTION_LIST
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def sanitize_tool_name(name: str) -> str:
|
|
67
|
+
"""Sanitize a Lambda function name to be used as a tool name."""
|
|
68
|
+
# Remove prefix if present
|
|
69
|
+
if name.startswith(FUNCTION_PREFIX):
|
|
70
|
+
name = name[len(FUNCTION_PREFIX) :]
|
|
71
|
+
|
|
72
|
+
# Replace invalid characters with underscore
|
|
73
|
+
name = re.sub(r'[^a-zA-Z0-9_]', '_', name)
|
|
74
|
+
|
|
75
|
+
# Ensure name doesn't start with a number
|
|
76
|
+
if name and name[0].isdigit():
|
|
77
|
+
name = '_' + name
|
|
78
|
+
|
|
79
|
+
return name
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def format_lambda_response(function_name: str, payload: bytes) -> str:
|
|
83
|
+
"""Format the Lambda function response payload."""
|
|
84
|
+
try:
|
|
85
|
+
# Try to parse the payload as JSON
|
|
86
|
+
payload_json = json.loads(payload)
|
|
87
|
+
return f'Function {function_name} returned: {json.dumps(payload_json, indent=2)}'
|
|
88
|
+
except (json.JSONDecodeError, UnicodeDecodeError):
|
|
89
|
+
# Return raw payload if not JSON
|
|
90
|
+
return f'Function {function_name} returned payload: {payload}'
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
async def invoke_lambda_function_impl(function_name: str, parameters: dict, ctx: Context) -> str:
|
|
94
|
+
"""Tool that invokes an AWS Lambda function with a JSON payload."""
|
|
95
|
+
await ctx.info(f'Invoking {function_name} with parameters: {parameters}')
|
|
96
|
+
|
|
97
|
+
response = lambda_client.invoke(
|
|
98
|
+
FunctionName=function_name,
|
|
99
|
+
InvocationType='RequestResponse',
|
|
100
|
+
Payload=json.dumps(parameters),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
await ctx.info(f'Function {function_name} returned with status code: {response["StatusCode"]}')
|
|
104
|
+
|
|
105
|
+
if 'FunctionError' in response:
|
|
106
|
+
error_message = (
|
|
107
|
+
f'Function {function_name} returned with error: {response["FunctionError"]}'
|
|
108
|
+
)
|
|
109
|
+
await ctx.error(error_message)
|
|
110
|
+
return error_message
|
|
111
|
+
|
|
112
|
+
payload = response['Payload'].read()
|
|
113
|
+
# Format the response payload
|
|
114
|
+
return format_lambda_response(function_name, payload)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def get_schema_from_registry(schema_arn: str) -> Optional[dict]:
|
|
118
|
+
"""Fetch schema from EventBridge Schema Registry.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
schema_arn: ARN of the schema to fetch
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
Schema content if successful, None if failed
|
|
125
|
+
"""
|
|
126
|
+
try:
|
|
127
|
+
# Parse registry name and schema name from ARN
|
|
128
|
+
# ARN format: arn:aws:schemas:region:account:schema/registry-name/schema-name
|
|
129
|
+
arn_parts = schema_arn.split(':')
|
|
130
|
+
if len(arn_parts) < 6:
|
|
131
|
+
logger.error(f'Invalid schema ARN format: {schema_arn}')
|
|
132
|
+
return None
|
|
133
|
+
|
|
134
|
+
registry_schema = arn_parts[5].split('/')
|
|
135
|
+
if len(registry_schema) != 3:
|
|
136
|
+
logger.error(f'Invalid schema path in ARN: {arn_parts[5]}')
|
|
137
|
+
return None
|
|
138
|
+
|
|
139
|
+
registry_name = registry_schema[1]
|
|
140
|
+
schema_name = registry_schema[2]
|
|
141
|
+
|
|
142
|
+
# Get the latest schema version
|
|
143
|
+
response = schemas_client.describe_schema(
|
|
144
|
+
RegistryName=registry_name,
|
|
145
|
+
SchemaName=schema_name,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# Return the raw schema content
|
|
149
|
+
return response['Content']
|
|
150
|
+
|
|
151
|
+
except Exception as e:
|
|
152
|
+
logger.error(f'Error fetching schema from registry: {e}')
|
|
153
|
+
return None
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def create_lambda_tool(function_name: str, description: str, schema_arn: Optional[str] = None):
|
|
157
|
+
"""Create a tool function for a Lambda function.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
function_name: Name of the Lambda function
|
|
161
|
+
description: Base description for the tool
|
|
162
|
+
schema_arn: Optional ARN of the input schema in the Schema Registry
|
|
163
|
+
"""
|
|
164
|
+
# Create a meaningful tool name
|
|
165
|
+
tool_name = sanitize_tool_name(function_name)
|
|
166
|
+
|
|
167
|
+
# Define the inner function
|
|
168
|
+
async def lambda_function(parameters: dict, ctx: Context) -> str:
|
|
169
|
+
"""Tool for invoking a specific AWS Lambda function with parameters."""
|
|
170
|
+
# Use the same implementation as the generic invoke function
|
|
171
|
+
return await invoke_lambda_function_impl(function_name, parameters, ctx)
|
|
172
|
+
|
|
173
|
+
# Set the function's documentation
|
|
174
|
+
if schema_arn:
|
|
175
|
+
schema = get_schema_from_registry(schema_arn)
|
|
176
|
+
if schema:
|
|
177
|
+
# We add the schema to the description because mcp.tool does not expose overriding the tool schema.
|
|
178
|
+
description_with_schema = f'{description}\n\nInput Schema:\n{schema}'
|
|
179
|
+
lambda_function.__doc__ = description_with_schema
|
|
180
|
+
logger.info(f'Added schema from registry to description for function {function_name}')
|
|
181
|
+
else:
|
|
182
|
+
lambda_function.__doc__ = description
|
|
183
|
+
else:
|
|
184
|
+
lambda_function.__doc__ = description
|
|
185
|
+
|
|
186
|
+
logger.info(f'Registering tool {tool_name} with description: {description}')
|
|
187
|
+
# Apply the decorator manually with the specific name
|
|
188
|
+
decorated_function = mcp.tool(name=tool_name)(lambda_function)
|
|
189
|
+
|
|
190
|
+
return decorated_function
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def get_schema_arn_from_function_arn(function_arn: str) -> Optional[str]:
|
|
194
|
+
"""Get schema ARN from function tags if configured.
|
|
195
|
+
|
|
196
|
+
Args:
|
|
197
|
+
function_arn: ARN of the Lambda function
|
|
198
|
+
|
|
199
|
+
Returns:
|
|
200
|
+
Schema ARN if found and configured, None otherwise
|
|
201
|
+
"""
|
|
202
|
+
if not FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY:
|
|
203
|
+
logger.info(
|
|
204
|
+
'No schema tag environment variable provided (FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY ).'
|
|
205
|
+
)
|
|
206
|
+
return None
|
|
207
|
+
|
|
208
|
+
try:
|
|
209
|
+
tags_response = lambda_client.list_tags(Resource=function_arn)
|
|
210
|
+
tags = tags_response.get('Tags', {})
|
|
211
|
+
if FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY in tags:
|
|
212
|
+
return tags[FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY]
|
|
213
|
+
else:
|
|
214
|
+
logger.info(
|
|
215
|
+
f'No schema arn provided for function {function_arn} via tag {FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY}'
|
|
216
|
+
)
|
|
217
|
+
except Exception as e:
|
|
218
|
+
logger.warning(f'Error checking tags for function {function_arn}: {e}')
|
|
219
|
+
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def filter_functions_by_tag(functions, tag_key, tag_value):
|
|
224
|
+
"""Filter Lambda functions by a specific tag key-value pair.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
functions: List of Lambda function objects
|
|
228
|
+
tag_key: Tag key to filter by
|
|
229
|
+
tag_value: Tag value to filter by
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
List of Lambda functions that have the specified tag key-value pair
|
|
233
|
+
"""
|
|
234
|
+
logger.info(f'Filtering functions by tag key-value pair: {tag_key}={tag_value}')
|
|
235
|
+
tagged_functions = []
|
|
236
|
+
|
|
237
|
+
for function in functions:
|
|
238
|
+
try:
|
|
239
|
+
# Get tags for the function
|
|
240
|
+
tags_response = lambda_client.list_tags(Resource=function['FunctionArn'])
|
|
241
|
+
tags = tags_response.get('Tags', {})
|
|
242
|
+
|
|
243
|
+
# Check if the function has the specified tag key-value pair
|
|
244
|
+
if tag_key in tags and tags[tag_key] == tag_value:
|
|
245
|
+
tagged_functions.append(function)
|
|
246
|
+
except Exception as e:
|
|
247
|
+
logger.warning(f'Error getting tags for function {function["FunctionName"]}: {e}')
|
|
248
|
+
|
|
249
|
+
logger.info(f'{len(tagged_functions)} Lambda functions found with tag {tag_key}={tag_value}.')
|
|
250
|
+
return tagged_functions
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def register_lambda_functions():
|
|
254
|
+
"""Register Lambda functions as individual tools."""
|
|
255
|
+
try:
|
|
256
|
+
logger.info('Registering Lambda functions as individual tools...')
|
|
257
|
+
functions = lambda_client.list_functions()
|
|
258
|
+
|
|
259
|
+
# Get all functions
|
|
260
|
+
all_functions = functions['Functions']
|
|
261
|
+
logger.info(f'Total Lambda functions found: {len(all_functions)}')
|
|
262
|
+
|
|
263
|
+
# First filter by function name if prefix or list is set
|
|
264
|
+
if FUNCTION_PREFIX or FUNCTION_LIST:
|
|
265
|
+
valid_functions = [
|
|
266
|
+
f for f in all_functions if validate_function_name(f['FunctionName'])
|
|
267
|
+
]
|
|
268
|
+
logger.info(f'{len(valid_functions)} Lambda functions found after name filtering.')
|
|
269
|
+
else:
|
|
270
|
+
valid_functions = all_functions
|
|
271
|
+
logger.info(
|
|
272
|
+
'No name filtering applied (both FUNCTION_PREFIX and FUNCTION_LIST are empty).'
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
# Then filter by tag if both FUNCTION_TAG_KEY and FUNCTION_TAG_VALUE are set and non-empty
|
|
276
|
+
if FUNCTION_TAG_KEY and FUNCTION_TAG_VALUE:
|
|
277
|
+
tagged_functions = filter_functions_by_tag(
|
|
278
|
+
valid_functions, FUNCTION_TAG_KEY, FUNCTION_TAG_VALUE
|
|
279
|
+
)
|
|
280
|
+
valid_functions = tagged_functions
|
|
281
|
+
elif FUNCTION_TAG_KEY or FUNCTION_TAG_VALUE:
|
|
282
|
+
logger.warning(
|
|
283
|
+
'Both FUNCTION_TAG_KEY and FUNCTION_TAG_VALUE must be set to filter by tag.'
|
|
284
|
+
)
|
|
285
|
+
valid_functions = []
|
|
286
|
+
|
|
287
|
+
for function in valid_functions:
|
|
288
|
+
function_name = function['FunctionName']
|
|
289
|
+
description = function.get('Description', f'AWS Lambda function: {function_name}')
|
|
290
|
+
schema_arn = get_schema_arn_from_function_arn(function['FunctionArn'])
|
|
291
|
+
|
|
292
|
+
create_lambda_tool(function_name, description, schema_arn)
|
|
293
|
+
|
|
294
|
+
logger.info('Lambda functions registered successfully as individual tools.')
|
|
295
|
+
|
|
296
|
+
except Exception as e:
|
|
297
|
+
logger.error(f'Error registering Lambda functions as tools: {e}')
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def main():
|
|
301
|
+
"""Run the MCP server with CLI argument support."""
|
|
302
|
+
mcp.run()
|
|
303
|
+
|
|
304
|
+
register_lambda_functions()
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
if __name__ == '__main__':
|
|
308
|
+
main()
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: awslabs.lambda-tool-mcp-server
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: An AWS Labs Model Context Protocol (MCP) server for AWS Lambda Tools
|
|
5
|
+
Project-URL: Homepage, https://awslabs.github.io/mcp/
|
|
6
|
+
Project-URL: Documentation, https://awslabs.github.io/mcp/servers/lambda-tool-mcp-server/
|
|
7
|
+
Project-URL: Source, https://github.com/awslabs/mcp.git
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/awslabs/mcp/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/awslabs/mcp/blob/main/src/lambda-tool-mcp-server/CHANGELOG.md
|
|
10
|
+
Author: Amazon Web Services
|
|
11
|
+
Author-email: AWSLabs MCP <203918161+awslabs-mcp@users.noreply.github.com>
|
|
12
|
+
License: Apache-2.0
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
License-File: NOTICE
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: boto3>=1.37.27
|
|
25
|
+
Requires-Dist: mcp[cli]>=1.6.0
|
|
26
|
+
Requires-Dist: pydantic>=2.10.6
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# AWS Lambda Tool MCP Server
|
|
30
|
+
|
|
31
|
+
A Model Context Protocol (MCP) server for AWS Lambda to select and run Lambda function as MCP tools without code changes.
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
This MCP server acts as a **bridge** between MCP clients and AWS Lambda functions, allowing generative AI models to access and run Lambda functions as tools. This is useful, for example, to access private resources such as internal applications and databases without the need to provide public network access. This approach allows the model to use other AWS services, private networks, and the public internet.
|
|
36
|
+
|
|
37
|
+
```mermaid
|
|
38
|
+
graph LR
|
|
39
|
+
A[Model] <--> B[MCP Client]
|
|
40
|
+
B <--> C["MCP2Lambda<br>(MCP Server)"]
|
|
41
|
+
C <--> D[Lambda Function]
|
|
42
|
+
D <--> E[Other AWS Services]
|
|
43
|
+
D <--> F[Internet]
|
|
44
|
+
D <--> G[VPC]
|
|
45
|
+
|
|
46
|
+
style A fill:#f9f,stroke:#333,stroke-width:2px
|
|
47
|
+
style B fill:#bbf,stroke:#333,stroke-width:2px
|
|
48
|
+
style C fill:#bfb,stroke:#333,stroke-width:4px
|
|
49
|
+
style D fill:#fbb,stroke:#333,stroke-width:2px
|
|
50
|
+
style E fill:#fbf,stroke:#333,stroke-width:2px
|
|
51
|
+
style F fill:#dff,stroke:#333,stroke-width:2px
|
|
52
|
+
style G fill:#ffd,stroke:#333,stroke-width:2px
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
From a **security** perspective, this approach implements segregation of duties by allowing the model to invoke the Lambda functions but not to access the other AWS services directly. The client only needs AWS credentials to invoke the Lambda functions. The Lambda functions can then interact with other AWS services (using the function role) and access public or private networks.
|
|
56
|
+
|
|
57
|
+
## Prerequisites
|
|
58
|
+
|
|
59
|
+
1. Install `uv` from [Astral](https://docs.astral.sh/uv/getting-started/installation/) or the [GitHub README](https://github.com/astral-sh/uv#installation)
|
|
60
|
+
2. Install Python using `uv python install 3.10`
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
Here are some ways you can work with MCP across AWS, and we'll be adding support to more products including Amazon Q Developer CLI soon: (e.g. for Amazon Q Developer CLI MCP, `~/.aws/amazonq/mcp.json`):
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"mcpServers": {
|
|
69
|
+
"awslabs.lambda-tool-mcp-server": {
|
|
70
|
+
"command": "uvx",
|
|
71
|
+
"args": ["awslabs.lambda-tool-mcp-server@latest"],
|
|
72
|
+
"env": {
|
|
73
|
+
"AWS_PROFILE": "your-aws-profile",
|
|
74
|
+
"AWS_REGION": "us-east-1",
|
|
75
|
+
"FUNCTION_PREFIX": "your-function-prefix",
|
|
76
|
+
"FUNCTION_LIST": "your-first-function, your-second-function",
|
|
77
|
+
"FUNCTION_TAG_KEY": "your-tag-key",
|
|
78
|
+
"FUNCTION_TAG_VALUE": "your-tag-value",
|
|
79
|
+
"FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY": "your-function-tag-for-input-schema"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
or docker after a successful `docker build -t awslabs/bedrock-kb-retrieval-mcp-server .`:
|
|
87
|
+
|
|
88
|
+
```file
|
|
89
|
+
# fictitious `.env` file with AWS temporary credentials
|
|
90
|
+
AWS_ACCESS_KEY_ID=ASIAIOSFODNN7EXAMPLE
|
|
91
|
+
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
92
|
+
AWS_SESSION_TOKEN=AQoEXAMPLEH4aoAH0gNCAPy...truncated...zrkuWJOgQs8IZZaIv2BXIa2R4Olgk
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"mcpServers": {
|
|
98
|
+
"awslabs.lambda-tool-mcp-server": {
|
|
99
|
+
"command": "docker",
|
|
100
|
+
"args": [
|
|
101
|
+
"run",
|
|
102
|
+
"--rm",
|
|
103
|
+
"--interactive",
|
|
104
|
+
"--env",
|
|
105
|
+
"AWS_REGION=us-east-1",
|
|
106
|
+
"--env",
|
|
107
|
+
"FUNCTION_PREFIX=your-function-prefix",
|
|
108
|
+
"--env",
|
|
109
|
+
"FUNCTION_LIST=your-first-function,your-second-function",
|
|
110
|
+
"--env",
|
|
111
|
+
"FUNCTION_TAG_KEY=your-tag-key",
|
|
112
|
+
"--env",
|
|
113
|
+
"FUNCTION_TAG_VALUE=your-tag-value",
|
|
114
|
+
"--env",
|
|
115
|
+
"FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY=your-function-tag-for-input-schema",
|
|
116
|
+
"--env-file",
|
|
117
|
+
"/full/path/to/file/above/.env",
|
|
118
|
+
"awslabs/lambda-tool-mcp-server:latest"
|
|
119
|
+
],
|
|
120
|
+
"env": {},
|
|
121
|
+
"disabled": false,
|
|
122
|
+
"autoApprove": []
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
NOTE: Your credentials will need to be kept refreshed from your host
|
|
129
|
+
|
|
130
|
+
The `AWS_PROFILE` and the `AWS_REGION` are optional, their default values are `default` and `us-east-1`.
|
|
131
|
+
|
|
132
|
+
You can specify `FUNCTION_PREFIX`, `FUNCTION_LIST`, or both. If both are empty, all functions pass the name check.
|
|
133
|
+
After the name check, if both `FUNCTION_TAG_KEY` and `FUNCTION_TAG_VALUE` are set, functions are further filtered by tag (with key=value).
|
|
134
|
+
If only one of `FUNCTION_TAG_KEY` and `FUNCTION_TAG_VALUE`, then no function is selected and a warning is displayed.
|
|
135
|
+
|
|
136
|
+
**IMPORTANT**: The function name is used as MCP tool name. The function description in AWS Lambda is used as MCP tool description. The function description should clarify when to use the function (what it provides) and how (which parameters). For example, a function that gives access to an internal Customer Relationship Management (CRM) system can use this description:
|
|
137
|
+
```plaintext
|
|
138
|
+
Retrieve customer status on the CRM system based on { 'customerId' } or { 'customerEmail' }
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The lambda function parameters can also be provided through the EventBridge Schema Registry, which provides formal JSON Schema. See [Schema Support](#schema-support) below.
|
|
142
|
+
|
|
143
|
+
Sample functions that can be deployed via AWS SAM are provided in the `examples` folder.
|
|
144
|
+
|
|
145
|
+
## Schema Support
|
|
146
|
+
|
|
147
|
+
The Lambda MCP Server supports input schema through AWS EventBridge Schema Registry. This provides formal JSON Schema documentation for your Lambda function inputs.
|
|
148
|
+
|
|
149
|
+
### Configuration
|
|
150
|
+
|
|
151
|
+
To use schema validation:
|
|
152
|
+
|
|
153
|
+
1. Create your schema in EventBridge Schema Registry
|
|
154
|
+
2. Tag your Lambda function with the schema ARN:
|
|
155
|
+
```plaintext
|
|
156
|
+
Key: FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY (configurable)
|
|
157
|
+
Value: arn:aws:schemas:region:account:schema/registry-name/schema-name
|
|
158
|
+
```
|
|
159
|
+
3. Configure the MCP server with the tag key:
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"env": {
|
|
163
|
+
"FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY": "your-schema-arn-tag-key"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
When a Lambda function has a schema tag, the MCP server will:
|
|
169
|
+
1. Fetch the schema from EventBridge Schema Registry
|
|
170
|
+
2. Add the schema to the tool's documentation
|
|
171
|
+
|
|
172
|
+
This provides better documentation compared to describing parameters in the function description.
|
|
173
|
+
|
|
174
|
+
## Best practices
|
|
175
|
+
|
|
176
|
+
- Use the `FUNCTION_LIST` to specify the functions that are available as MCP tools.
|
|
177
|
+
- Use the `FUNCTION_PREFIX` to specify the prefix of the functions that are available as MCP tools.
|
|
178
|
+
- Use the `FUNCTION_TAG_KEY` and `FUNCTION_TAG_VALUE` to specify the tag key and value of the functions that are available as MCP tools.
|
|
179
|
+
- AWS Lambda `Description` property: the description of the function is used as MCP tool description, so it should be very detailed to help the model understand when and how to use the function
|
|
180
|
+
- Use EventBridge Schema Registry to provide formal input validation:
|
|
181
|
+
- Create JSON Schema definitions for your function inputs
|
|
182
|
+
- Tag functions with their schema ARNs
|
|
183
|
+
- Configure `FUNCTION_INPUT_SCHEMA_ARN_TAG_KEY` in the MCP server
|
|
184
|
+
|
|
185
|
+
## Security Considerations
|
|
186
|
+
|
|
187
|
+
When using this MCP server, you should consider:
|
|
188
|
+
|
|
189
|
+
- Only Lambda functions that are in the provided list or with a name starting with the prefix are imported as MCP tools.
|
|
190
|
+
- The MCP server needs permissions to invoke the Lambda functions.
|
|
191
|
+
- Each Lambda function has its own permissions to optionally access other AWS resources.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
awslabs/__init__.py,sha256=4zfFn3N0BkvQmMTAIvV_QAbKp6GWzrwaUN17YeRoChM,115
|
|
2
|
+
awslabs/lambda_tool_mcp_server/__init__.py,sha256=x7AwppTJLpTQeKBYa6m_TpxWsPbCwkXn1Ef9C3z8j18,60
|
|
3
|
+
awslabs/lambda_tool_mcp_server/server.py,sha256=s2y_j9bbFHx6wuLyyxSsKwLEXwsIZIflLH56GKnJZGM,11061
|
|
4
|
+
awslabs_lambda_tool_mcp_server-2.0.0.dist-info/METADATA,sha256=4GPG3GC3I_WyYW7g0rn-47T_GnaSjPL3uN-PTRwdI2g,8309
|
|
5
|
+
awslabs_lambda_tool_mcp_server-2.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
+
awslabs_lambda_tool_mcp_server-2.0.0.dist-info/entry_points.txt,sha256=rrFa2w8xVmgRcyIKtNoXWx76PHwrBvqoufkPkBZSNOc,94
|
|
7
|
+
awslabs_lambda_tool_mcp_server-2.0.0.dist-info/licenses/LICENSE,sha256=CeipvOyAZxBGUsFoaFqwkx54aPnIKEtm9a5u2uXxEws,10142
|
|
8
|
+
awslabs_lambda_tool_mcp_server-2.0.0.dist-info/licenses/NOTICE,sha256=ib9Otj6ggtcDIF7sDYoJ58elbhar_1fvoQdIB4Ym4k8,98
|
|
9
|
+
awslabs_lambda_tool_mcp_server-2.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|