Aller au contenu

Leçon 17 · Tools, Terminal and MCP

Connecting MCP Servers

Connect tools to Cursor with the Model Context Protocol: configure mcp.json for local and remote servers, keep secrets safe, and manage approvals and risk.

The agent can work with your files and terminal. It does not automatically have your issue tracker, design tool or internal documentation. The Model Context Protocol (MCP) is an open standard that lets a program called an MCP server offer tools and data to AI applications. The MCP lesson explains the protocol; here you configure it for Cursor.

Where configuration lives

Scope File
One project .cursor/mcp.json in the project root
All your projects ~/.cursor/mcp.json

Hosted cloud agents do not read your personal file. They use the servers configured for them in your account or team.

Local and remote servers

Servers go under a top-level mcpServers object, with one key for each server. A local server using the stdio transport is a program started on your computer. It needs a command, and may have args, env and envFile. A remote server needs a url, and may have headers. Remote servers can also use OAuth sign-in.

This example uses made-up names and addresses:

JSON
{
  "mcpServers": {
    "team-docs": {
      "command": "python",
      "args": ["${workspaceFolder}/tools/docs_server.py"],
      "env": { "DOCS_TOKEN": "${env:DOCS_TOKEN}" }
    },
    "issue-tracker": {
      "url": "https://mcp.example.com/mcp",
      "headers": { "Authorization": "Bearer ${env:TRACKER_TOKEN}" }
    }
  }
}

${env:NAME} reads an environment variable, and ${workspaceFolder} is the project root. This lets you commit the file without committing secrets. The documentation advises using environment variables for secrets and never writing them into the file.

Check a configuration

This real script checks the basic shape of a configuration and warns about values that look like hard-coded secrets. The checks are our own, not the product's validator.

Python Check an mcp.json file

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Approvals

By default, Cursor asks before it uses an MCP tool, and you can expand the prompt to see the arguments. Read the arguments. A tool that adds a comment may seem harmless, but the comment text could contain private data.

MCP calls follow the same run modes as terminal commands. In Auto-review, allowlisted tools run at once and other calls go to the classifier. The mcpAllowlist in permissions.json uses server:tool entries. Allow specific read tools rather than server:*, unless you are sure that every present and future tool on that server is harmless.

Think before you connect

An MCP server is code with access. A local one typically runs on your machine with your user's permissions. A remote one receives whatever arguments the agent sends. The documentation recommends:

  • Install servers only from trusted sources.
  • Review which data and APIs they access.
  • Use restricted keys with the fewest permissions.
  • Audit the code for critical integrations.

There is also a quieter risk. Tool descriptions and tool results can become part of the model's context. A harmful server, or a hostile ticket returned by an honest server, can try to give the agent instructions. Prefer read-only access, and require approval for writing, sending and deleting.

Also remember that .cursorignore does not stop MCP tools from reaching ignored files.

A permission plan

Write one before you connect a server:

Tool (made-up example) Effect Policy
search_issues Reads Allow
read_issue Reads text that others wrote Allow, but check what follows
add_comment Writes, visible to others Ask
delete_issue Destroys Do not enable
Python Stand-in: apply a permission plan to tool calls

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

This stand-in uses "deny unless listed", a good principle for your planning. The product's real approval behavior follows its run mode and settings.

Troubleshooting

Open the Output panel (Ctrl+Shift+U, or Cmd+Shift+U on a Mac) and choose MCP Logs to find connection, sign-in or crash errors. Then check that the command exists, the URL is correct, and the environment variables are visible to the editor. An app that was started before you set a variable may need a restart.

Add one server at a time

A careful first connection looks like this:

  1. Read the server's documentation and, if you can, its source code. Note who publishes it.
  2. Create a new token for it with read-only access to test data.
  3. Add it to the project file, with the token as an environment variable.
  4. Restart if needed, and look at the list of tools it offers.
  5. Ask for one harmless read, and inspect the arguments and the result.
  6. Decide which tools to allow, which to ask about and which to disable.

Record why the project needs the server and who owns its token. Later, remove servers that nobody uses, and revoke their tokens. Check again after a server is updated, because new tools or changed descriptions can change its risk. For local servers installed from a package registry, prefer a fixed version over whatever is newest.

Common mistakes

  • Pasting a token directly into a file that you commit.
  • Connecting many servers "just in case". Each adds risk, and tool definitions take context space.
  • Giving a server an administrator key when read access is enough.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Which field does a local stdio server need?

    A local server is started with a command; remote servers use a url.
  2. 2. What is the best way to give a server a token in a shared file?

    Environment interpolation keeps the secret out of version control.
  3. 3. Why should you be careful with tool results?

    Untrusted text in results can attempt prompt injection.

Summary

  • MCP servers add tools; configure them in the project or global mcp.json.
  • Local servers use command; remote ones use url.
  • Keep secrets in environment variables and use minimal permissions.
  • Read arguments, limit write actions and distrust outside text.

Next: Hooks: Automate and Guard the Agent

Votre progression est enregistrée dans ce navigateur. Aucun compte nécessaire.