Skip to content

fix(iam-mcp-server): inject ctx instead of requiring it - #4838

Open
mangeshraut712 wants to merge 7 commits into
awslabs:mainfrom
mangeshraut712:cursor/iam-mcp-ctx-field-ed4d
Open

mangeshraut712 wants to merge 7 commits into
awslabs:mainfrom
mangeshraut712:cursor/iam-mcp-ctx-field-ed4d

Conversation

@mangeshraut712

@mangeshraut712 mangeshraut712 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4675

Problem

list_users, get_user, and create_user annotated ctx as CallToolResult. Because the MCP SDK only injects parameters annotated with its Context type, it exposed ctx as a required client argument and calls failed with ctx Field required.

Change

Annotate those parameters as mcp.server.mcpserver.Context, imported as McpContext to avoid colliding with the server-local Context class. The SDK now injects the request context instead of publishing it in the tool schema.

As a result:

  • list_users accepts an empty argument object.
  • get_user and create_user require only user_name among the affected required inputs.

Verification

  • test_user_tools_do_not_require_ctx verifies that ctx is absent from each public tool schema and invokes all three tools through mcp.call_tool without a client-supplied context.
  • src/iam-mcp-server/run_tests.sh passed: Ruff lint and format checks, Pyright with 0 errors, and 232 passing tests.

Compatibility

No breaking API change.

Checklist

  • I have reviewed the contributing guidelines.
  • I have performed a self-review of this change.
  • Changes have been tested.
  • Changes are documented.

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.

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

Fixes #4675

Why: list_users / get_user / create_user annotated ctx as CallToolResult, so the SDK exposed it as a required client field (ctx Field required).

What: Annotate as mcp.server.mcpserver.Context (imported as McpContext) so the SDK injects context instead of publishing it in the tool schema.

Test: test_user_tools_do_not_require_ctx; run_tests.sh — ruff, pyright 0 errors, 232 tests passed.

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

CI is green. Injects ctx instead of requiring it on the IAM tools. Please review and merge when you can.

list_users, get_user, and create_user annotated ctx as CallToolResult, so
the SDK treated it as a required argument and every call failed with
"ctx Field required". Annotate ctx as the MCP Context so the server
injects it.
@mangeshraut712
mangeshraut712 force-pushed the cursor/iam-mcp-ctx-field-ed4d branch from f64d0cf to 9e554ef Compare October 27, 2026 14:24

This branch has not been deployed

No deployments
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 1.1.1: list_users/get_user still fail with "ctx Field required"

1 participant