A Model Context Protocol (MCP) server for comprehensive AWS Identity and Access Management (IAM) operations. This server provides AI assistants with the ability to manage IAM users, roles, policies, and permissions while following security best practices.
- User Management: Create, list, retrieve, and delete IAM users
- Role Management: Create, list, and manage IAM roles with trust policies
- Group Management: Create, list, retrieve, and delete IAM groups with member management
- Policy Management: List and manage IAM policies (managed and inline)
- Inline Policy Management: Full CRUD operations for user and role inline policies
- Permission Management: Attach/detach policies to users and roles
- Access Key Management: Create and delete access keys for users
- Security Simulation: Test policy permissions before applying them
- Policy Simulation: Test permissions without making changes
- Force Delete: Safely remove users with all associated resources
- Permissions Boundary Support: Set permission boundaries for enhanced security
- Trust Policy Validation: Validate JSON trust policies for roles
- Read-Only Mode: Run server in read-only mode to prevent any modifications
- Follows AWS IAM security best practices
- Supports principle of least privilege
- Provides warnings for sensitive operations
- Includes comprehensive error handling
# Install using uv (recommended)
uv tool install awslabs.iam-mcp-server
# Or install using pip
pip install awslabs.iam-mcp-serverThe server requires AWS credentials to be configured. You can use any of the following methods:
-
AWS Profile (recommended):
export AWS_PROFILE=your-profile-name -
Environment Variables:
export AWS_ACCESS_KEY_ID=your-access-key export AWS_SECRET_ACCESS_KEY=your-secret-key export AWS_REGION=us-east-1
-
IAM Roles (for EC2/Lambda): The server will automatically use IAM roles when running on AWS services.
The AWS credentials used by this server need the following IAM permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:ListUsers",
"iam:GetUser",
"iam:CreateUser",
"iam:DeleteUser",
"iam:ListRoles",
"iam:GetRole",
"iam:CreateRole",
"iam:DeleteRole",
"iam:ListGroups",
"iam:GetGroup",
"iam:CreateGroup",
"iam:DeleteGroup",
"iam:AddUserToGroup",
"iam:RemoveUserFromGroup",
"iam:AttachGroupPolicy",
"iam:DetachGroupPolicy",
"iam:ListAttachedGroupPolicies",
"iam:ListGroupPolicies",
"iam:ListPolicies",
"iam:GetPolicy",
"iam:CreatePolicy",
"iam:DeletePolicy",
"iam:AttachUserPolicy",
"iam:DetachUserPolicy",
"iam:AttachRolePolicy",
"iam:DetachRolePolicy",
"iam:ListAttachedUserPolicies",
"iam:ListAttachedRolePolicies",
"iam:ListUserPolicies",
"iam:ListRolePolicies",
"iam:GetUserPolicy",
"iam:GetRolePolicy",
"iam:PutUserPolicy",
"iam:PutRolePolicy",
"iam:GetGroupsForUser",
"iam:ListAccessKeys",
"iam:CreateAccessKey",
"iam:DeleteAccessKey",
"iam:SimulatePrincipalPolicy",
"iam:RemoveUserFromGroup",
"iam:DeleteUserPolicy",
"iam:DeleteRolePolicy"
],
"Resource": "*"
}
]
}Add to your ~/.aws/amazonq/mcp.json:
{
"mcpServers": {
"awslabs.iam-mcp-server": {
"command": "uvx",
"args": ["awslabs.iam-mcp-server@latest"],
"env": {
"AWS_PROFILE": "your-aws-profile",
"AWS_REGION": "us-east-1",
"FASTMCP_LOG_LEVEL": "ERROR"
}
}
}
}Add to your cline_mcp_settings.json:
{
"mcpServers": {
"awslabs.iam-mcp-server": {
"command": "uvx",
"args": ["awslabs.iam-mcp-server@latest"],
"env": {
"AWS_PROFILE": "your-aws-profile",
"AWS_REGION": "us-east-1",
"FASTMCP_LOG_LEVEL": "ERROR"
}
}
}
}| Cursor | VS Code |
|---|---|
Add to your .cursor/mcp.json:
{
"mcpServers": {
"awslabs.iam-mcp-server": {
"command": "uvx",
"args": ["awslabs.iam-mcp-server@latest"],
"env": {
"AWS_PROFILE": "your-aws-profile",
"AWS_REGION": "us-east-1",
"FASTMCP_LOG_LEVEL": "ERROR"
}
}
}
}The server supports a read-only mode that prevents all mutating operations while still allowing read operations. This is useful for:
- Safety: Preventing accidental modifications in production environments
- Testing: Allowing safe exploration of IAM resources without risk of changes
- Auditing: Running the server in environments where only read access should be allowed
Add the --readonly flag when starting the server:
# Using uvx
uvx awslabs.iam-mcp-server@latest --readonly
# Or if installed locally
python -m awslabs.iam_mcp_server.server --readonly{
"mcpServers": {
"awslabs.iam-mcp-server": {
"command": "uvx",
"args": ["awslabs.iam-mcp-server@latest", "--readonly"],
"env": {
"AWS_PROFILE": "your-aws-profile",
"AWS_REGION": "us-east-1"
}
}
}
}Simply add "--readonly" to the args array in your MCP configuration.
When read-only mode is enabled, the following operations will return an error:
create_userdelete_usercreate_roleattach_user_policydetach_user_policycreate_access_keydelete_access_key
These operations continue to work normally:
list_usersget_userlist_roleslist_policiessimulate_principal_policy
List IAM users in the account with optional filtering.
Parameters:
path_prefix(optional): Path prefix to filter users (e.g., "/division_abc/")max_items(optional): Maximum number of users to return (default: 100)
Get detailed information about a specific IAM user including attached policies, groups, and access keys.
Parameters:
user_name: The name of the IAM user to retrieve
Create a new IAM user.
Parameters:
user_name: The name of the new IAM userpath(optional): The path for the user (default: "/")permissions_boundary(optional): ARN of the permissions boundary policy
Delete an IAM user with optional force cleanup.
Parameters:
user_name: The name of the IAM user to deleteforce(optional): Force delete by removing all attached resources first (default: false)
List IAM roles in the account with optional filtering.
Parameters:
path_prefix(optional): Path prefix to filter roles (e.g., "/service-role/")max_items(optional): Maximum number of roles to return (default: 100)
Create a new IAM role with a trust policy.
Parameters:
role_name: The name of the new IAM roleassume_role_policy_document: The trust policy document in JSON formatpath(optional): The path for the role (default: "/")description(optional): Description of the rolemax_session_duration(optional): Maximum session duration in seconds (default: 3600)permissions_boundary(optional): ARN of the permissions boundary policy
List IAM groups in the account with optional filtering.
Parameters:
path_prefix(optional): Path prefix to filter groups (e.g., "/division_abc/")max_items(optional): Maximum number of groups to return (default: 100)
Get detailed information about a specific IAM group including members, attached policies, and inline policies.
Parameters:
group_name: The name of the IAM group to retrieve
Create a new IAM group.
Parameters:
group_name: The name of the new IAM grouppath(optional): The path for the group (default: "/")
Delete an IAM group with optional force cleanup.
Parameters:
group_name: The name of the IAM group to deleteforce(optional): Force delete by removing all members and policies first (default: false)
Add a user to an IAM group.
Parameters:
group_name: The name of the IAM groupuser_name: The name of the IAM user
Remove a user from an IAM group.
Parameters:
group_name: The name of the IAM groupuser_name: The name of the IAM user
Attach a managed policy to an IAM group.
Parameters:
group_name: The name of the IAM grouppolicy_arn: The ARN of the policy to attach
Detach a managed policy from an IAM group.
Parameters:
group_name: The name of the IAM grouppolicy_arn: The ARN of the policy to detach
List IAM policies in the account.
Parameters:
scope(optional): Scope of policies to list: "All", "AWS", or "Local" (default: "Local")only_attached(optional): Only return policies that are attached (default: false)path_prefix(optional): Path prefix to filter policiesmax_items(optional): Maximum number of policies to return (default: 100)
Attach a managed policy to an IAM user.
Parameters:
user_name: The name of the IAM userpolicy_arn: The ARN of the policy to attach
Detach a managed policy from an IAM user.
Parameters:
user_name: The name of the IAM userpolicy_arn: The ARN of the policy to detach
Create a new access key for an IAM user.
Parameters:
user_name: The name of the IAM user
Delete an access key for an IAM user.
Parameters:
user_name: The name of the IAM useraccess_key_id: The access key ID to delete
Simulate IAM policy evaluation for a principal to test permissions.
Parameters:
policy_source_arn: ARN of the user or role to simulateaction_names: List of actions to simulateresource_arns(optional): List of resource ARNs to test againstcontext_entries(optional): Context entries for the simulation
Create or update an inline policy for an IAM user.
Parameters:
user_name: The name of the IAM userpolicy_name: The name of the inline policypolicy_document: The policy document in JSON format (string or dict)
Retrieve an inline policy for an IAM user.
Parameters:
user_name: The name of the IAM userpolicy_name: The name of the inline policy
Delete an inline policy from an IAM user.
Parameters:
user_name: The name of the IAM userpolicy_name: The name of the inline policy to delete
List all inline policies for an IAM user.
Parameters:
user_name: The name of the IAM user
Create or update an inline policy for an IAM role.
Parameters:
role_name: The name of the IAM rolepolicy_name: The name of the inline policypolicy_document: The policy document in JSON format (string or dict)
Retrieve an inline policy for an IAM role.
Parameters:
role_name: The name of the IAM rolepolicy_name: The name of the inline policy
Delete an inline policy from an IAM role.
Parameters:
role_name: The name of the IAM rolepolicy_name: The name of the inline policy to delete
List all inline policies for an IAM role.
Parameters:
role_name: The name of the IAM role
# List all users
users = await list_users()
# Get specific user details
user_details = await get_user(user_name="john.doe")
# Create a new user
new_user = await create_user(
user_name="jane.smith",
path="/developers/"
)
# Delete a user (with force cleanup)
await delete_user(user_name="old.user", force=True)# Create a role for EC2 instances
trust_policy = {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"Service": "ec2.amazonaws.com"},
"Action": "sts:AssumeRole"
}
]
}
role = await create_role(
role_name="EC2-S3-Access-Role",
assume_role_policy_document=json.dumps(trust_policy),
description="Role for EC2 instances to access S3"
)# Create a new group
group = await create_group(
group_name="Developers",
path="/teams/"
)
# Add users to the group
await add_user_to_group(
group_name="Developers",
user_name="john.doe"
)
# Attach a policy to the group
await attach_group_policy(
group_name="Developers",
policy_arn="arn:aws:iam::123456789012:policy/DeveloperPolicy"
)
# Get group details including members
group_details = await get_group(group_name="Developers")# List customer managed policies
policies = await list_policies(scope="Local", only_attached=True)
# Attach a policy to a user
await attach_user_policy(
user_name="developer",
policy_arn="arn:aws:iam::123456789012:policy/DeveloperPolicy"
)# Test if a user can perform specific actions
simulation = await simulate_principal_policy(
policy_source_arn="arn:aws:iam::123456789012:user/developer",
action_names=["s3:GetObject", "s3:PutObject"],
resource_arns=["arn:aws:s3:::my-bucket/*"]
)# Create an inline policy for a user
policy_document = {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::my-bucket/*"
}
]
}
await put_user_policy(
user_name="developer",
policy_name="S3AccessPolicy",
policy_document=policy_document
)
# Retrieve an inline policy
policy = await get_user_policy(
user_name="developer",
policy_name="S3AccessPolicy"
)
# List all inline policies for a user
policies = await list_user_policies(user_name="developer")
# Create an inline policy for a role
await put_role_policy(
role_name="EC2-S3-Access-Role",
policy_name="S3ReadOnlyPolicy",
policy_document={
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "*"
}
]
}
)
# Delete an inline policy
await delete_user_policy(
user_name="developer",
policy_name="S3AccessPolicy"
)- Principle of Least Privilege: Always grant the minimum permissions necessary
- Use Roles for Applications: Prefer IAM roles over users for applications
- Regular Access Reviews: Periodically review and clean up unused users and permissions
- Access Key Rotation: Regularly rotate access keys
- Enable MFA: Use multi-factor authentication where possible
- Permissions Boundaries: Use permissions boundaries to set maximum permissions
- Policy Simulation: Test policies before applying them to production
- Prefer Managed Policies: Use managed policies over inline policies for reusable permissions
- Inline Policy Guidelines: Use inline policies only for permissions unique to a single identity
The server provides comprehensive error handling with descriptive messages:
- Authentication Errors: Clear messages for credential issues
- Permission Errors: Specific information about missing permissions
- Resource Not Found: Helpful messages when resources don't exist
- Validation Errors: Detailed feedback on invalid parameters
# Install development dependencies
uv sync --dev
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=awslabs.iam_mcp_server# Install in development mode
uv pip install -e .
# Run the server directly
python -m awslabs.iam_mcp_server.serverContributions are welcome! Please see the main repository's CONTRIBUTING.md for guidelines.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
For issues and questions:
- Check the AWS IAM documentation
- Review the MCP specification
- Open an issue in the GitHub repository
See CHANGELOG.md for version history and changes.