Overview
The Swarms TypeScript MCP Server bridges MCP-compatible agents (Claude Desktop, Cursor IDE, OpenAI Agents, and other MCP clients) with the Swarms AI agent platform. Built with Stainless and following the Model Context Protocol standard, this server exposes Swarms’ API endpoints as discoverable tools that agents can invoke directly—enabling agents to execute single agents, orchestrate multi-agent swarms, run reasoning workflows, and process batch operations without custom API integration code.Key Capabilities
- Single Agent Execution: Run individual Swarms agents with custom tasks, model selection, and configuration parameters
- Multi-Agent Orchestration: Coordinate swarms using architectural patterns including sequential workflows, concurrent execution, hierarchical structures, graph-based routing, and majority voting
- Reasoning Agents: Execute chain-of-thought reasoning agents for step-by-step problem analysis and complex decision-making
- Batch Processing: Process multiple agent tasks or swarm operations in parallel using thread pools for high-throughput workloads
- Dynamic Discovery: Use runtime endpoint discovery to explore available API operations, or configure static tool exposure for better performance and type safety
- Client Optimization: Automatically adapts tool schemas and capabilities to match your MCP client (Claude Desktop, Cursor IDE, OpenAI Agents, Claude Code, and custom clients)
Why Use This Server?
The Swarms MCP Server eliminates the need to write custom API integration code when building agent-powered applications. Instead of manually constructing HTTP requests, handling authentication, and parsing responses, agents can directly invoke Swarms operations through standardized MCP tools. The server provides production-ready error handling, rate limit monitoring, health checks, and flexible configuration options—allowing you to expose only the tools your agents need while maintaining full compatibility with the MCP ecosystem.Table of Contents
- Installation
- Configuration
- Tool Exposure Strategies
- Client Compatibility
- Available Tools and Resources
- Advanced Usage
- Error Handling
- Best Practices
- Client Setup Examples
Installation
Prerequisites
- Node.js (version 14 or higher recommended)
- A valid Swarms API key
- An MCP-compatible client application
Method 1: Direct Invocation via npx
For quick testing or one-time usage, you can run the MCP server directly without installation:Method 2: Installation via npm
For persistent usage or integration into projects:Method 3: MCP Client Configuration
Most MCP clients support configuration through a JSON file. Add the following configuration to your client’s MCP server settings:your_api_key_here with your actual Swarms API key.
Configuration
Environment Variables
The server requires the following environment variable:SWARMS_API_KEY: Your Swarms platform API key (required)
Command-Line Arguments
The MCP server supports extensive command-line configuration:Tool Selection
--tools=all: Expose all available tools--tools=dynamic: Enable dynamic tool discovery mode--tool=<name>: Include a specific tool by name--no-tool=<name>: Exclude a specific tool by name
Resource Filtering
--resource=<name>: Include all tools under a specific resource--resource=<pattern>*: Include resources matching a wildcard pattern--no-resource=<name>: Exclude a specific resource
Operation Filtering
--operation=read: Include only read operations (GET/LIST)--operation=write: Include only write operations (POST/PUT/DELETE)
Client Configuration
--client=<type>: Configure for a specific MCP client- Valid values:
openai-agents,claude,claude-code,cursor
- Valid values:
Capability Settings
--capability=<name>: Enable specific client capabilitiestop-level-unions: Support for top-level union typesvalid-json: JSON string parsing for argumentsrefs: Support for $ref pointers in schemasunions: Support for union types (anyOf)formats: Support for format validationstool-name-length=N: Maximum tool name length
Utility Commands
--list: Display all available tools--help: Show help information
Configuration Examples
Filter for read-only operations on a specific resource:Tool Exposure Strategies
The Swarms MCP server offers two primary strategies for exposing API endpoints as tools:Static Tool Exposure
In this mode, each API endpoint is exposed as a dedicated tool with a fully-defined schema. This approach provides:- Better autocomplete and type safety in client applications
- More accurate parameter validation
- Clearer documentation for each endpoint
- Optimal performance for smaller API surfaces
Dynamic Tool Discovery
When configured with--tools=dynamic, the server exposes three meta-tools that enable runtime endpoint discovery:
list_api_endpoints
Discovers available endpoints with optional search filtering.
Parameters:
search(optional): Query string to filter endpoints
get_api_endpoint_schema
Retrieves detailed schema information for a specific endpoint.
Parameters:
endpoint: The name or identifier of the endpoint
invoke_api_endpoint
Executes any endpoint with appropriate parameters.
Parameters:
endpoint: The endpoint to invokeparameters: JSON object containing endpoint-specific parameters
- Working with a large API surface
- Context window limitations are a concern
- Runtime endpoint discovery is required
- The full API schema exceeds available context
Hybrid Approach
You can combine both strategies by specifying explicit tools alongside dynamic tools:Client Compatibility
Different MCP clients have varying capabilities for handling tool schemas and complex types. The Swarms MCP server automatically adapts its output based on the specified client.Supported Clients
Claude (--client=claude)
Optimized for Claude AI assistant with full schema support.
Claude Code (--client=claude-code)
Configured for the Claude Code command-line environment.
Cursor (--client=cursor)
Adapted for the Cursor IDE with appropriate schema simplifications.
OpenAI Agents (--client=openai-agents)
Compatible with OpenAI’s agent framework.
Manual Capability Configuration
For clients not listed above or to override defaults:top-level-unions: Enables union types at the schema rootvalid-json: Enables JSON string parsing for complex argumentsrefs: Enables JSON Schema $ref pointersunions: Enables anyOf union typesformats: Enables format validators (date-time, email, etc.)tool-name-length=N: Sets maximum tool name length
Available Tools and Resources
The Swarms MCP server exposes 12 tools by default when using--tools=all. These tools are organized by resource and operation type, providing comprehensive access to the Swarms API functionality.
Complete Tools Reference Table
| Tool Name | Resource | Operation Type | Description | Primary Use Case |
|---|---|---|---|---|
get_root_client | $client | Read | Root client information | API connectivity verification and health checks |
check_health | health | Read | Health status of the Swarms API | Monitoring API uptime and status |
run_agent | agent | Write | Execute a single agent with a specified task | Running individual AI agents for specific tasks |
run_agent_batch | agent.batch | Write | Execute multiple agents concurrently using thread pool | Parallel processing of multiple independent agent tasks |
list_available_models | models | Read | Retrieve all available AI models | Model discovery and selection for agent configuration |
check_available_swarms | swarms | Read | Query available swarm types and configurations | Determining which swarm architecture to use |
get_logs_swarms | swarms | Read | Retrieve API request logs for associated API keys | Auditing, debugging, and usage analysis |
run_swarms | swarms | Write | Execute a swarm with a specified task | Orchestrating multiple agents in coordinated patterns |
run_swarms_batch | swarms.batch | Write | Execute multiple swarms concurrently using thread pool | Large-scale parallel swarm processing |
create_completion_reasoning_agents | reasoning_agents | Write | Execute a reasoning agent with chain-of-thought | Complex problem-solving requiring step-by-step analysis |
list_types_reasoning_agents | reasoning_agents | Read | List available reasoning agent types | Selecting appropriate reasoning strategies |
get_limits_client_rate | client.rate | Read | Query rate limits and current usage statistics | Monitoring API quota and preventing rate limit violations |
Dynamic Discovery Tools
When using--tools=dynamic, these additional meta-tools become available:
| Tool Name | Description | Parameters |
|---|---|---|
list_api_endpoints | Discover available endpoints with optional filtering | search (optional): Query string to filter endpoints |
get_api_endpoint_schema | Retrieve detailed schema for a specific endpoint | endpoint: Endpoint name or identifier |
invoke_api_endpoint | Execute any endpoint with appropriate parameters | endpoint: Endpoint to invokeparameters: JSON object with endpoint-specific parameters |
Resource: $client
get_root_client (read)- Description: Root client information
- Use case: Health checks and API connectivity verification
Resource: health
check_health (read)- Description: Health status of the Swarms API
- Returns: API health metrics and status
- Use case: Monitoring and uptime verification
Resource: agent
run_agent (write)- Description: Execute a single agent with a specified task
- Parameters:
task: The task description for the agent- Additional agent configuration parameters
- Returns: Agent execution results
- Use case: Running individual AI agents for specific tasks
Resource: agent.batch
run_agent_batch (write)- Description: Execute multiple agents concurrently using a thread pool
- Parameters:
tasks: Array of task descriptions- Batch configuration options
- Returns: Aggregated results from all agents
- Use case: Parallel processing of multiple independent tasks
Resource: models
list_available_models (read)- Description: Retrieve all available AI models
- Returns: List of model identifiers and capabilities
- Use case: Model discovery and selection
Resource: swarms
check_available_swarms (read)- Description: Query available swarm types and configurations
- Returns: List of swarm architectures and their capabilities
- Use case: Determining which swarm pattern to use
- Description: Retrieve API request logs for all associated API keys
- Returns: Log entries (excluding client IP information)
- Use case: Auditing, debugging, and usage analysis
- Description: Execute a swarm with a specified task
- Parameters:
task: The task for the swarm to executeswarm_type: The type of swarm architecture- Additional swarm configuration
- Returns: Swarm execution results
- Use case: Orchestrating multiple agents in coordinated patterns
Resource: swarms.batch
run_swarms_batch (write)- Description: Execute multiple swarms concurrently using a thread pool
- Parameters:
tasks: Array of swarm tasks- Batch and swarm configuration
- Returns: Aggregated swarm results
- Use case: Large-scale parallel swarm processing
Resource: reasoning_agents
create_completion_reasoning_agents (write)- Description: Execute a reasoning agent with chain-of-thought capabilities
- Parameters:
task: The reasoning task- Reasoning configuration options
- Returns: Reasoning output with intermediate steps
- Use case: Complex problem-solving requiring step-by-step analysis
- Description: List available reasoning agent types
- Returns: Reasoning agent architectures and their characteristics
- Use case: Selecting appropriate reasoning strategies
Resource: client.rate
get_limits_client_rate (read)- Description: Query rate limits and current usage
- Returns: Rate limit information and usage statistics
- Use case: Monitoring API quota and preventing rate limit violations
Tools by Operation Type
The 12 default tools are divided into read and write operations:Read Operations (7 tools)
Read operations are safe, idempotent operations that retrieve information without modifying state:get_root_clientcheck_healthlist_available_modelscheck_available_swarmsget_logs_swarmslist_types_reasoning_agentsget_limits_client_rate
list_api_endpointsget_api_endpoint_schema
Write Operations (5 tools)
Write operations execute actions and may modify state or consume resources:run_agentrun_agent_batchrun_swarmsrun_swarms_batchcreate_completion_reasoning_agents
invoke_api_endpoint
Advanced Usage
Programmatic Integration
For custom integrations, you can import and configure the server programmatically:Importing Specific Tools
Creating Custom Endpoints
Error Handling
When integrating with the Swarms MCP server, implement appropriate error handling:Common Error Scenarios
- Authentication Errors: Invalid or missing API key
- Rate Limiting: Exceeded API quota
- Invalid Parameters: Malformed requests or missing required fields
- Network Issues: Connectivity problems or timeouts
- Resource Unavailability: Requested models or swarm types not available
Best Practices for Error Management
- Always validate the presence of the
SWARMS_API_KEYenvironment variable - Implement retry logic with exponential backoff for transient failures
- Monitor rate limits using
get_limits_client_ratebefore heavy operations - Log errors with sufficient context for debugging
- Provide meaningful error messages to end users
Best Practices
| Best Practice Category | Recommendation | Description/Details |
|---|---|---|
| Batch Operations | Use batch endpoints | When processing multiple tasks, prefer batch endpoints to reduce overhead. |
| Tool Exposure | Filter unnecessary tools | Minimize context window usage by exposing only the tools required for your workflow. |
| Rate Limit Monitoring | Monitor rate limits | Regularly check your usage with get_limits_client_rate to avoid hitting rate limits. |
| Model List Optimization | Cache model lists | Store the output of list_available_models to prevent repeated, redundant API calls. |
| API Key Security | Secure API key storage | Never commit API keys to version control; use secure secrets management. |
| Environment Management | Use environment variables | Manage sensitive information via secure environment variable configuration. |
| Access Control | Limit tool exposure by permission | Restrict tool access based on user permissions when possible. |
| Audit Logging | Utilize audit logging | Use get_logs_swarms for security auditing and tracking usage. |
| Tool Strategy (Exploration) | Start with dynamic tools | Use --tools=dynamic during early exploration and development to discover available endpoints. |
| Tool Strategy (Production) | Transition to static tool exposure | Once requirements are clear, switch to static tool exposure for performance and predictability. |
| Tool Filter Testing | Test tool/resource/operation filters | Verify your configurations (--tool, --resource, --operation) to ensure only expected endpoints are exposed. |
| Client Compatibility | Test with target client | Always verify integration and tool compatibility with your specific client setup. |
| Version Management | Pin production versions | Specify the exact package version (e.g., [email protected]) in production deployments. |
| Health Monitoring | Implement health checks | Regularly call check_health to ensure server and API availability. |
| API Reliability | Handle API unavailability gracefully | Implement graceful degradation strategies for scenarios when the API is down. |
| Internal Documentation | Maintain documentation of exposed tools | Keep internal documentation up-to-date on which tools/endpoints are available and why they’re exposed. |
Client Setup Examples
Claude Code
Claude Code is a command-line tool that enables Claude to interact with your codebase and execute operations. Here’s how to configure the Swarms MCP server for Claude Code.Configuration
Add the Swarms MCP server to your Claude Code configuration file (typically located at~/.config/claude-code/mcp.json or similar):
Recommended Configuration for Claude Code
For optimal performance with Claude Code, consider using a focused set of tools:Usage Example: Running an Agent
Once configured, you can ask Claude Code to execute Swarms agents directly:run_agent tool:
Usage Example: Batch Processing
For processing multiple files or tasks:Usage Example: Multi-Agent Swarm
For complex tasks requiring multiple agents:Usage Example: Reasoning Agent
For complex problem-solving tasks:Dynamic Tool Discovery
If you prefer runtime discovery, configure with dynamic tools:Claude Chat (Claude Desktop)
Claude Chat (Claude Desktop) provides a conversational interface where Claude can use MCP tools to interact with the Swarms API.Configuration
Add the Swarms MCP server to your Claude Desktop configuration file. On macOS, this is typically located at~/Library/Application Support/Claude/claude_desktop_config.json:
Recommended Configuration for Claude Chat
For Claude Chat, you may want to expose all tools for maximum flexibility:Usage Example: Health Check
Start by verifying the connection:Usage Example: Agent Execution
Execute agents through natural conversation:Usage Example: Model Discovery
Discover available models before running agents:Usage Example: Swarm Orchestration
Use multi-agent swarms for complex workflows:Usage Example: Rate Limit Monitoring
Check your API usage:Filtered Configuration Example
If you want to limit Claude Chat to read-only operations:check_health, list_available_models, check_available_swarms, and get_limits_client_rate, preventing accidental execution of agents or swarms.
Resources
| Resource | Link |
|---|---|
| GitHub Repository | swarms-ts GitHub |
| npm Package | swarms-ts-mcp on npm |
| Model Context Protocol | modelcontextprotocol.io |
| License | Apache-2.0 |
Version Information
- Current Version: 0.1.0-alpha.10
- Status: Alpha release
- Last Updated: 6 months ago
Support
For issues, feature requests, or contributions:- Open an issue on the GitHub repository
- Review existing documentation and examples
- Check the Model Context Protocol specification for general MCP questions