Skip to content

Conversation

zach-snell
Copy link

@zach-snell zach-snell commented Oct 7, 2025

Summary

Fixes #1463

The IAM MCP server was incorrectly using CallToolResult as the type annotation for the ctx parameter in tool handlers, causing it to be exposed in the tool schema. FastMCP automatically excludes Context typed parameters from schemas, so changing to the correct type resolves the validation errors.

Problem

When clients attempted to call IAM server tools, they received validation errors:

1 validation error for list_usersArguments
ctx
  Field required

The tool schema incorrectly included ctx in the required parameters, even though FastMCP is supposed to automatically inject this parameter and exclude it from the schema.

Root Cause

The server was using the wrong type annotation:

  • Incorrect: ctx: CallToolResult (from mcp.types) - gets exposed in schema
  • Correct: ctx: Context (from mcp.server.fastmcp) - automatically excluded

Changes Made

  • ✅ Changed ctx: CallToolResultctx: Context in 3 tool signatures:
    • list_users
    • get_user
    • create_user
  • ✅ Updated imports to use Context from mcp.server.fastmcp
  • ✅ Renamed internal Context class to ServerContext to avoid naming collision
  • ✅ Updated all 20 internal context references

Testing

Created comprehensive test script (test-iam-ctx-fix.py) that verifies:

  1. ctx parameter is not present in tool schema
  2. ✅ Tools can be called without passing ctx
  3. ✅ Tool calls succeed and return expected data

Test results:

✅ PASS: ctx is not in the schema
   Properties: ['path_prefix', 'max_items']
✅ PASS: Tool call succeeded!
   Retrieved 0 users

Checklist

  • Code follows project conventions
  • Fix tested with MCP client
  • No breaking changes to public API
  • Internal context class renamed to avoid collision
  • All affected tools verified

Acknowledgment

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

@zach-snell zach-snell requested review from a team and oshardik as code owners October 7, 2025 04:10
@zach-snell zach-snell force-pushed the fix/iam-server-ctx-parameter-1463 branch from f083975 to ca8b0e9 Compare October 7, 2025 04:13
…ter (awslabs#1463)

FastMCP automatically excludes `Context` typed parameters from tool schemas,
but was exposing `CallToolResult` typed ctx parameters, causing validation
errors when clients attempted to call tools.

Changes:
- Replace `ctx: CallToolResult` with `ctx: Context` in tool signatures
- Update imports: use `Context` from `mcp.server.fastmcp`
- Rename internal Context class to ServerContext to avoid naming collision
- Update all internal context references (20 occurrences)

Affected tools:
- list_users
- get_user
- create_user

Fixes awslabs#1463
@zach-snell zach-snell force-pushed the fix/iam-server-ctx-parameter-1463 branch from ca8b0e9 to f109703 Compare October 7, 2025 20:28
Copy link

codecov bot commented Oct 10, 2025

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.46%. Comparing base (008d5fa) to head (e5057ac).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...rc/iam-mcp-server/awslabs/iam_mcp_server/server.py 95.45% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1464      +/-   ##
==========================================
- Coverage   89.46%   89.46%   -0.01%     
==========================================
  Files         726      726              
  Lines       50359    50358       -1     
  Branches     7954     7954              
==========================================
- Hits        45054    45053       -1     
  Misses       3450     3450              
  Partials     1855     1855              

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

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

2 participants