Cursor MCP Server Shows "No tools available" for `@21st-dev/magic`
When configuring Cursor's MCP (Managed Code Provider) servers, the `@21st-dev/magic` tool is not being recognized, resulting in the "No tools available" message within the Cursor interface. Despite a seemingly correct configuration in the ~/.cursor/mcp.json file, Cursor fails to identify and utilize the tool's capabilities.
The core problem lies in how the `@21st-dev/magic` MCP server is being launched and how it communicates with Cursor. The provided MCP logs indicate a failure to establish a stable connection, leading to the "Connection closed" error. The "No server info found" error further suggests that Cursor is unable to properly initialize and maintain a connection with the `@21st-dev/magic` server.
Root Cause Analysis
While the exact root cause requires further investigation, several potential issues could be contributing to the problem:
- Incorrect Argument Handling: The
API_KEY="xxxxxxxxxx"argument might not be correctly passed or interpreted by the `@21st-dev/magic` tool. Environment variables are often a more robust way to pass sensitive information. - Process Termination: The
npxcommand might be terminating prematurely if `@21st-dev/magic` doesn't maintain a persistent connection or encounters an error during initialization. - MCP Protocol Incompatibility: The `@21st-dev/magic` tool might not be fully compliant with the MCP protocol expected by Cursor, especially regarding the exchange of server information and tool offerings.
- Version Incompatibility: The
@latesttag might be pulling a version of `@21st-dev/magic` that is incompatible with the current version of Cursor's MCP implementation.
Solution
Here's a step-by-step approach to troubleshoot and resolve the issue:
- Environment Variable Configuration: Modify the
mcp.jsonconfiguration to use an environment variable for the API key. First, set the environment variable in your shell (e.g.,export MAGIC_API_KEY="xxxxxxxxxx"). Then, update themcp.jsonfile: - Pin a Specific Version: Replace
@latestwith a specific, known-working version of `@21st-dev/magic`. This helps isolate version incompatibility issues: - Verify MCP Compliance: Ensure that `@21st-dev/magic` correctly implements the MCP protocol, including proper handling of
ListOfferingsrequests and the establishment of a persistent connection. Refer to Cursor's MCP documentation or examples for guidance. - Examine `@21st-dev/magic` Output: Modify the
commandandargsto redirect the output of `@21st-dev/magic` to a file. This can provide valuable debugging information: - Restart Cursor: After making any changes to
mcp.json, restart Cursor to ensure the new configuration is loaded.
{
"mcpServers": {
"@21st-dev/magic": {
"command": "npx",
"args": [
"-y",
"@21st-dev/magic@latest"
],
"env": {
"API_KEY": "$MAGIC_API_KEY"
}
}
}
}
{
"mcpServers": {
"@21st-dev/magic": {
"command": "npx",
"args": [
"-y",
"@21st-dev/magic@1.2.3"
],
"env": {
"API_KEY": "$MAGIC_API_KEY"
}
}
}
}
{
"mcpServers": {
"@21st-dev/magic": {
"command": "bash",
"args": [
"-c",
"npx -y @21st-dev/magic@latest API_KEY=\"$MAGIC_API_KEY\" > /tmp/magic_mcp.log 2>&1"
]
}
}
}
Then, examine the contents of /tmp/magic_mcp.log for any error messages or unexpected behavior.
Practical Tips and Considerations
- MCP Server Stability: Ensure that the MCP server process remains active and responsive after initialization. Cursor relies on a persistent connection to the server.
- Error Handling: Implement robust error handling within the `@21st-dev/magic` tool to gracefully handle unexpected situations and provide informative error messages to Cursor.
- Logging: Incorporate comprehensive logging within `@21st-dev/magic` to aid in debugging and troubleshooting connection issues.
- Consult Documentation: Refer to both Cursor's MCP documentation and `@21st-dev/magic`'s documentation for specific requirements and best practices.
- Test with a Minimal Configuration: Start with a very simple configuration of `@21st-dev/magic` to rule out complex configuration issues. Gradually add complexity as you verify each component.