Grokking the Model Context Protocol (MCP)
Vote

0% completed

​

Connecting Your First Server to a Host

Two Ways to Connect

A Local Server

What Happens at Startup

What the Host Shows

What You Approve

A Remote Server

When It Does Not Work

What Costbook Must Provide

Key Takeaways

Practice Questions

In about ten minutes, you will do four things:

  1. Add a local server to a host by editing one configuration file.
  2. Restart the host and read the list of tools that the server offers.
  3. Ask for something that needs a tool, and answer the host's approval question.
  4. Add a remote server by entering a URL, and sign in if the server asks.

No Costbook code is needed yet, because the servers already exist. The official MCP documentation uses Claude Desktop as its example host, and this lesson follows it. Other hosts use different file names and menus, and menus change between releases. The lesson therefore explains what each setting means, and the documentation shows where to click.

Two Ways to Connect

A host needs different information for a local server and for a remote server. It must start a local server as a process, so it needs a command to run. A remote server is already running, so the host needs only its URL and a way for the user to sign in.

Local serverRemote server
<span style="white-space:nowrap">What you give the host</span>A command, its arguments, and environment variablesA URL
<span style="white-space:nowrap">What the host does</span>Starts the server as a processSends HTTP requests to the URL
<span style="white-space:nowrap">Your identity</span>The server runs with your permissions, and you do not sign inYou sign in, if the server requires it
<span style="white-space:nowrap">What you install</span>The server program and what it needs to runNothing
A local server is configured with a command, arguments, and environment variables. A remote server is configured with a URL and a sign-in.
A local server is configured with a command, arguments, and environment variables. A remote server is configured with a URL and a sign-in.

Look at the top box of each column. The left box describes how to start a program, and the right box gives only an address.

A Local Server

The example is the Filesystem Server from the official guide to local servers. It reads and writes files in the folders that you name, like the files server that reads the employee's receipts folder. It is a Node.js program, so Node.js must be installed first.

Claude Desktop lists its local servers in one JSON file, which you open from the Developer section of its settings. Put this in the file, with a folder that exists on your machine:

{ "mcpServers": { "filesystem": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-filesystem", "/Users/username/Receipts" ] } } }

Each key has one meaning:

  • mcpServers contains one entry for each local server.
  • filesystem is a name that you choose for the server. The host shows it in its list of servers.
  • command is the program that the host runs. Here it is npx, a Node.js tool that installs a package and runs it.
  • args is the list of arguments that the host passes to the command. The first, -y, lets npx install the package without asking for confirmation, and the second names the package. Every argument after that is a folder that this server may use.

A third key, env, sets environment variables for the server's process. A local server that calls a product's API can read its API key from such a variable. The documentation gives this generic example:

{ "mcpServers": { "myserver": { "command": "mcp-server-myapp", "env": { "MYAPP_API_KEY": "some_key" } } } }

Write folder paths in full, starting from the root of the disk. On Windows, the documentation doubles each backslash in a path, because a single backslash has a special meaning in JSON. Save the file, quit the host completely, and start it again.

What Happens at Startup

When the host starts, it reads the configuration and creates one MCP client for each server in it. For a local server, the client runs the command and exchanges messages with the new process through its standard input and output. For a remote server, the client sends its messages to the URL. In both cases, the client then asks the server for its tools with tools/list.

At startup, the host reads its configuration, starts or reaches each server, and lists the tools of each one.
At startup, the host reads its configuration, starts or reaches each server, and lists the tools of each one.

Notice that the list of tools comes from the server. The configuration file says only how to start the program, and it contains no tool names.

What the Host Shows

After the restart, open the host's list of connected servers. In Claude Desktop, you open it from a menu in the corner of the message box. Select filesystem, and the host shows the tools that the server returned: tools that read files, create files and folders, move and rename files, and search. Each entry is one definition, collected in step 1 of the previous lesson.

Now type a request that needs a tool, such as "Which files are in my Receipts folder?" The model asks for a tool call, but the host does not send it yet. It first shows you an approval question.

What You Approve

You make two separate decisions, and the first one matters more.

The first decision is to add the server. A local server runs with the permissions of your user account, so the program can do anything that you can do on that machine. The folders in args are a limit that this server applies to its own work, and the operating system does not enforce that limit.

Adding a server to the file therefore means that you trust the program and its author. The lesson on the risk of installing a server covers this decision.

The second decision is to approve one call. The approval question names the tool, and a host should also show the inputs that the model chose. Read both before you answer, and deny the call if it is not what you asked for.

A Remote Server

A remote server needs no file, no command, and no installation. In Claude, you add one in the settings as a custom connector by entering its URL. The official guide to remote servers offers a practice server at https://example-server.modelcontextprotocol.io/mcp.

Most remote servers must know who you are. When a server requires a sign-in, the host runs the sign-in before it finishes connecting. After that, the client lists the tools and the host shows them, as it does for a local server. On the same settings page, you can turn off individual tools of a connected server.

When It Does Not Work

The official debugging guide describes these three causes for a local server.

CauseWhy it happensRepair
<span style="white-space:nowrap">Wrong path or working directory</span>The host may start the server in an undefined working directory, so a relative path such as ./data does not lead to your folderWrite full paths in command and args
<span style="white-space:nowrap">Missing environment variable</span>A local server inherits only a limited set of environment variables automaticallyList every variable that the server needs under env
<span style="white-space:nowrap">The host was not fully restarted</span>The host loads the configuration when it starts, and closing its window may not stop itQuit the host completely, then open it again

If none of the three applies, check that the file is valid JSON, and then read the host's log files. A local server can write diagnostic messages to standard error, which is a second output of a process, separate from its normal output. Claude Desktop saves those messages in one log file for each server. The lesson on debugging with the Inspector covers these methods in detail.

What Costbook Must Provide

Costbook's data is on Costbook's own infrastructure, so its server is remote. A customer who connects it follows only the remote steps, and the Costbook team must therefore provide two things:

  • A URL. The server answers MCP requests at https://mcp.costbook.example/mcp, and an employee enters that address in the host.
  • A sign-in. The host sends the employee to Costbook's sign-in service at https://auth.costbook.example, which is called an authorization server. The employee signs in with an existing Costbook account and allows the host to act for that account.

A local Costbook server would instead require every employee to install a runtime, edit a JSON file, and copy an API key into env. The lesson on the authorization flow explains what happens during the sign-in.

Key Takeaways

  • A local server is configured with a command, its arguments, and environment variables, and the host starts it as a process.
  • A remote server is configured with a URL, and the host runs a sign-in when the server requires one.
  • At startup, the host creates one client for each configured server, and each client lists its server's tools.
  • Adding a local server means trusting a program that runs with your permissions. Approving a call covers only that one call and its inputs.
  • The three common failures of a local server are a relative path, a missing environment variable, and a host that was not fully restarted.
  • To let customers connect, the Costbook team must provide a URL and a sign-in.

A host and a server have now exchanged messages for you, but you have not read any of them. Requests, Results, Errors, and Notifications prints those messages and explains the four forms of an MCP message.

Practice Questions

1. A configuration contains "args": ["-y", "@modelcontextprotocol/server-filesystem", "./receipts"], and the server cannot find the folder. What is the likely cause?

<details><summary>Show answer</summary>

The path is relative. The host may start the server in an undefined working directory, so ./receipts does not lead to the folder that the user meant. The repair is to write the full path of the folder.

</details>

2. A colleague adds a server to the configuration file, closes the host's window, and opens it again. The new server does not appear. Why?

<details><summary>Show answer</summary>

The host was never stopped. It loads the configuration when it starts, and closing the window left the same process running. The colleague must quit the host completely and then start it.

</details>

3. The Filesystem Server is configured with one folder. A user says: "The approval question protects every file outside that folder." What is wrong with this statement?

<details><summary>Show answer</summary>

The approval question covers one call, and the folder limit is applied by the server program itself. The server runs with the user's permissions, so the operating system would let it read any file that the user can read. The files outside the folder are protected only if the program is honest and correct, which is why adding a server is a decision about trust.

</details>

4. Why does the Costbook team give its customers a URL and not a command to run?

<details><summary>Show answer</summary>

Costbook's data is on Costbook's infrastructure, and a remote server needs no installation. One server at one address serves every customer, and the sign-in tells it which user sent each request. A local server would require a runtime, a configuration file, and an API key on every employee's laptop.

</details>

Reading Progress

0%


Vote for new content

On This Page

Two Ways to Connect

A Local Server

What Happens at Startup

What the Host Shows

What You Approve

A Remote Server

When It Does Not Work

What Costbook Must Provide

Key Takeaways

Practice Questions