导航菜单

In the previous chapters, we successfully created an MCP Server. Now, we need to tell Cursor how to find and use this server. This is done through a configuration file.

Creating the Configuration File

  1. First, open any project in Cursor (it can be a new project or an existing one).

  2. Create a .cursor folder in the project root (if it doesn’t exist):

    mkdir .cursor
    
  3. Create an mcp.json file in the .cursor folder:

    touch .cursor/mcp.json
    
  4. Add the following configuration to the mcp.json file:

    {
        "mcpServers": {
            "about-me": {
                "command": "uv",
                "args": [
                    "--directory",
                    "/Users/{your_username}/Code/Playground/build_mcp_for_cursor/project",
                    "run",
                    "main.py"
                ]
            }
        }
    }
    

Understanding the Configuration

Let’s break down each part of this configuration file:

  1. mcpServers

    • This is the main section that defines all MCP servers
  2. about-me

    • This is our server name, which must match the name in FastMCP("about-me")
    • You can change this name, but ensure it matches in both places
  3. command

    • Specifies which command to use to run the server
    • We’re using uv, our package manager
  4. args

    • List of command arguments, including:
      • --directory: Specifies the project directory
      • Project path: You need to replace this with your actual project path
      • run: The uv run command
      • main.py: The Python file to run

Enabling the MCP Service

After creating the configuration file, we need to enable the service in Cursor:

  1. Open Cursor Settings

    • Windows/Linux: Click the gear icon in the bottom left or use Ctrl + ,
    • macOS: Click the gear icon in the bottom left or use Cmd + ,
  2. In the Settings panel:

    • Find and click “MCP” in the left sidebar
    • You should see our “about-me” service
    • Click the “Enabled” option to enable the service

Verifying the Service

Now we can test if our service is working:

  1. Open Cursor’s Agent mode

    • Click the AI icon in the sidebar
    • Or use the keyboard shortcut to open the AI panel
  2. Try these test questions:

    Q: What's my name?
    A: [AI will call get_user_name() and return "Lucas Lee"]
    
    Q: How old am I?
    A: [AI will call get_user_age() and return 30]
    

If you receive the correct answers, congratulations! Your MCP Server is configured and working properly!

Common Issues

  1. Can’t Find MCP Settings?

    • Ensure your Cursor is up to date
    • Try restarting Cursor IDE
  2. Service Appears Grayed Out?

    • Check if the configuration file format is correct
    • Ensure the project path is correct and accessible
  3. Agent Can’t Get Information?

    • Make sure the service is properly enabled
    • Check if the Python service is running
    • Look at Cursor’s log information

Next Steps

Now that you’ve successfully configured and tested your MCP Server, you can:

  • Add more custom tools
  • Modify the returned information
  • Implement more complex functionality
  • Explore other possibilities with MCP servers

搜索