Skip to content

mcp-lambda-handler: Docstring Parameter Parsing Fails with Type Hints #746

@andormarkus

Description

@andormarkus

Describe the bug

The docstring parameter parsing logic in mcp_lambda_handler.py fails to match parameter names when Google-style docstrings include type hints. The code splits parameter descriptions at the : character without considering that parameter names may contain type hints in parentheses (e.g., param1 (int): Description).

Expected Behavior

The docstring parser should correctly extract parameter names without type hints, so that:

  • param1 (int): The first parameter. extracts parameter name as param1
  • param2 (str): The second parameter. extracts parameter name as param2

This would allow the parameter matching logic to work correctly with Google-style docstrings that include type hints.

Current Behavior

When a docstring contains parameter descriptions with type hints like:

Args:
    param1 (int): The first parameter.
    param2 (str): The second parameter.

The parsing logic at line 198 extracts parameter names by splitting at the first : character:

param_name = line.split(":")[0].strip()

This results in parameter names like param1 (int) and param2 (str) being stored in the arg_descriptions dictionary.

However, at line 246, the code attempts to match these against actual function parameter names:

if param_name in arg_descriptions:

Since the actual parameter names (param1, param2) don't include type hints, the lookup fails and parameter descriptions are not found.

Reproduction Steps

  1. Create a Lambda function with a Google-style docstring containing type hints:

    def my_function(param1, param2):
        """
        Function description.
        
        Args:
            param1 (int): The first parameter.
            param2 (str): The second parameter.
        
        Returns:
            str: Result description.
        """
        pass
  2. Use the mcp_lambda_handler to process this function

  3. The parameter descriptions will not be properly matched due to the parsing issue

Possible Solution

Modify the parameter name extraction logic at line 198 to remove type hints from parameter names before storing them in arg_descriptions. For example:

# Extract parameter name, removing type hints if present
param_line = line.split(":")[0].strip()
# Remove type hints in parentheses (e.g., "param1 (int)" -> "param1")
param_name = param_line.split("(")[0].strip()

This would handle the common Google-style docstring format while maintaining backward compatibility with docstrings that don't include type hints.

Additional Information/Context

  • File: src/mcp-lambda-handler/awslabs/mcp_lambda_handler/mcp_lambda_handler.py
  • Problematic line: Line 198 (parameter name extraction)
  • Related line: Line 246 (parameter lookup)
  • Docstring format: Google-style docstrings as documented in sphinxcontrib-napoleon
  • Impact: Parameter descriptions are not properly associated with function parameters when type hints are present in docstrings

This is a straightforward fix that would improve compatibility with standard Python docstring conventions.

OS

MacOS

Server

mcp-lambda-handler

Server Version

No response

Region experiencing the issue

all

Other information

No response

Service quota

  • I have reviewed the service quotas for this construct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions