A clean, modular, and extensible Model Context Protocol (MCP) server that provides access to the Cursor Background Agents API. Built with TypeScript following SOLID principles and clean architecture patterns.
This MCP server enables AI applications to interact with Cursor's Background Agents API, allowing them to:
- Launch autonomous coding agents on GitHub repositories
- Monitor agent status and progress
- Add follow-up instructions to running agents
- Retrieve agent conversation history
- List available AI models for agents
- ✅ MCP Compliant: Fully implements the MCP specification
- ✅ Clean Architecture: Modular design with clear separation of concerns
- ✅ Type Safe: Written in TypeScript with comprehensive type definitions
- ✅ Input Validation: JSON Schema validation using AJV
- ✅ Error Handling: MCP-compliant structured error responses
- ✅ Comprehensive Tests: 54+ unit tests with high coverage
- ✅ Well Documented: Clear documentation and examples
src/
├── domain/ # Core business logic and types
├── application/ # Use cases and service interfaces
├── infrastructure/ # External API clients and adapters
└── presentation/ # HTTP endpoints and controllers
The server follows clean architecture principles with clear dependency inversion:
- Domain: Pure business logic, no external dependencies
- Application: Orchestrates domain logic and defines interfaces
- Infrastructure: Implements external integrations (Cursor API)
- Presentation: Handles HTTP requests and responses
-
Get your Cursor API key from Cursor Dashboard → Integrations
-
Add to your MCP settings in VS Code:
- Open VS Code
- Go to the Kilo Code extension settings
- Add this configuration to your
mcp_settings.json:
{
"cursor-background-agents": {
"command": "npx",
"args": [
"-y",
"cursor-background-agent-mcp-server"
],
"env": {
"CURSOR_API_KEY": "your-actual-cursor-api-key-here"
},
"disabled": false,
"autoApprove": [
"launchAgent",
"listAgents",
"listModels"
],
"alwaysAllow": [
"getAgentStatus",
"getAgentConversation",
"listAgents",
"listModels",
"listRepositories"
]
}
}- Start using the tools in your Kilo Code chat! The server will automatically start when needed.
For development or standalone usage:
- Clone the repository:
git clone <repository-url>
cd cursor-background-agent-mcp- Install dependencies:
npm install- Set environment variables:
export CURSOR_API_KEY="your-cursor-api-key"- Build the project:
npm run build- Run as MCP STDIO server:
npm run mcpOr run as HTTP server:
npm startOnce configured in your mcp_settings.json, you can use these tools directly in Kilo Code:
@kilo launch a new Cursor agent to add TypeScript types to my React components
@kilo check the status of my running Cursor agents
@kilo list all available AI models for Cursor agents
The server implements the Model Context Protocol via STDIO for VS Code integration, and also exposes HTTP endpoints for direct API access:
- Tools:
launchAgent,listAgents,listModels,addFollowup,getAgentConversation,getAgentStatus - Resources: None currently (extensible)
- Transport: JSON-RPC over STDIO
- GET
/manifest- Get available tools and schemas - POST
/tool-invoke- Invoke a tool - POST
/resource- Access a resource
Start a new background agent to work on a repository.
Input:
{
"prompt": {
"text": "string",
"images": [
{
"data": "base64-string",
"dimension": { "width": 1024, "height": 768 }
}
]
},
"source": {
"repository": "https://github.com/org/repo",
"ref": "main"
}
}Output:
{
"id": "bc_abc123",
"name": "Add README Documentation",
"status": "CREATING",
"source": { "repository": "...", "ref": "main" },
"target": {
"branchName": "cursor/add-readme-1234",
"url": "https://cursor.com/agents?id=bc_abc123",
"autoCreatePr": false
},
"createdAt": "2024-01-15T10:30:00Z"
}Retrieve all background agents for the authenticated user.
Input: {} (empty object)
Output:
{
"agents": [
{
"id": "bc_abc123",
"name": "Add README Documentation",
"status": "RUNNING",
"summary": "Added README.md with installation instructions",
"createdAt": "2024-01-15T10:30:00Z"
}
],
"nextCursor": "bc_def456"
}Get available AI models for background agents.
Input: {} (empty object)
Output:
{
"models": [
{ "name": "gpt-4", "recommended": true },
{ "name": "gpt-3.5", "recommended": false }
]
}Send additional instructions to a running agent.
Input:
{
"agentId": "bc_abc123",
"prompt": {
"text": "Also add a section about troubleshooting"
}
}Retrieve conversation history of an agent.
Input:
{
"agentId": "bc_abc123"
}Get current status and results of an agent.
Input:
{
"agentId": "bc_abc123"
}# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coveragesrc/
├── domain/
│ ├── index.ts # Domain types and interfaces
│ ├── manifest.ts # Tool/resource definitions
│ └── errors.ts # MCP error handling
├── application/
│ ├── index.ts # Application interfaces
│ └── toolExecutionService.ts # Tool execution logic
├── infrastructure/
│ ├── index.ts # Infrastructure interfaces
│ └── cursorApiClient.ts # Cursor API HTTP client
├── presentation/
│ ├── manifestController.ts # GET /manifest
│ ├── toolInvocationController.ts # POST /tool-invoke
│ └── resourceAccessController.ts # POST /resource
└── server.ts # Main server setup
- Define the tool schema in
src/domain/manifest.ts:
{
name: "newTool",
description: "Description of the new tool",
inputSchema: { /* JSON Schema */ },
outputSchema: { /* JSON Schema */ }
}- Implement the tool logic in
src/application/toolExecutionService.ts:
case "newTool":
return this.handleNewTool(input);-
Add corresponding API method in
src/infrastructure/cursorApiClient.tsif needed. -
Write tests in
src/__tests__/following existing patterns.
The server implements MCP-compliant error handling with structured error responses:
{
"error": {
"code": "TOOL_NOT_FOUND",
"message": "Tool 'invalidTool' not found",
"details": { /* optional additional context */ }
}
}Error codes include:
TOOL_NOT_FOUND/RESOURCE_NOT_FOUNDINVALID_INPUT/INVALID_OUTPUTSERVICE_UNAVAILABLEAUTHENTICATION_FAILEDRATE_LIMITEDTIMEOUTINTERNAL_ERROR
Environment variables:
| Variable | Description | Default |
|---|---|---|
CURSOR_API_KEY |
Your Cursor API key (required) | - |
PORT |
Server port | 3000 |
For detailed API documentation, see the Cursor Background Agents API docs.
This package is published to npm via automated GitHub Actions workflows. For detailed publishing instructions, see PUBLISHING.md.
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Make changes following the existing patterns
- Add tests for new functionality
- Run tests:
npm test - Submit a pull request
- Follow TypeScript best practices
- Use meaningful names for variables, functions, and classes
- Keep functions small and single-purpose
- Add JSDoc comments for public APIs
- Follow clean architecture principles
MIT License - see LICENSE file for details.