Skip to content

iam-mcp-server: Tool calls fail with ctx parameter validation error #1463

Description

@zach-snell

Describe the bug

The IAM MCP server tools cannot be called via MCP protocol because they incorrectly expose the internal ctx parameter in their tool schemas. This causes all tool calls to fail with a validation error requiring the ctx parameter.

Expected Behavior

Tool calls should succeed when called with only the documented parameters (e.g., path_prefix, max_items for list_users). The ctx parameter should be automatically injected by the FastMCP framework and excluded from the tool schema.

Current Behavior

Tool calls fail with validation error:

Error executing tool list_users: 1 validation error for list_usersArguments
ctx
  Field required [type=missing, input_value={'max_items': 5}, input_type=dict]

The tool schema incorrectly includes ctx as a required parameter with type CallToolResult.

Reproduction Steps

  1. Connect to IAM MCP server using official MCP Python SDK:
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

server_params = StdioServerParameters(
    command="uvx",
    args=["awslabs.iam-mcp-server@latest", "--readonly"],
    env={"AWS_PROFILE": "your-profile", "AWS_REGION": "us-east-1"}
)

async with stdio_client(server_params) as (read, write):
    async with ClientSession(read, write) as session:
        await session.initialize()
        # This call fails with ctx validation error
        result = await session.call_tool("list_users", arguments={})
  1. Observe validation error in result.content

Possible Solution

Change the ctx parameter type from CallToolResult to Context from mcp.server.fastmcp:

Current (incorrect):

from mcp.types import CallToolResult

@mcp.tool()
async def list_users(
    ctx: CallToolResult,  # Wrong type - gets exposed in schema
    path_prefix: Optional[str] = None,
    max_items: int = 100,
) -> UsersListResponse:

Fixed:

from mcp.server.fastmcp import Context

@mcp.tool()
async def list_users(
    ctx: Context,  # Correct type - automatically excluded from schema
    path_prefix: Optional[str] = None,
    max_items: int = 100,
) -> UsersListResponse:

This affects 3 tools: list_users, get_user, and create_user.

Additional Information/Context

  • The FastMCP framework automatically excludes parameters typed as Context from tool schemas
  • Using CallToolResult (from mcp.types) instead of Context (from mcp.server.fastmcp) causes the parameter to be exposed
  • This appears to be a typo/oversight from when the tools were created
  • No other tools in the server use ctx parameter, suggesting incomplete migration

Environment

OS: Linux (Ubuntu 22.04)
Server: iam-mcp-server
Server Version: 1.0.6
Region: us-east-1

Service Quota

  • I have reviewed the service quotas for this construct

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleThese are items that have been around for a long time without progress

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions