Skip to content
ImagineWorld

Consuming Servers

node_idnode-book_learn-model-context-protocol-with-python_chapter-08-consuming-servers
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num8
chapter_titleConsuming Servers
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

So far, we have looked at how to create servers, but also at consuming them via bespoke clients that you have to write yourself. In this section, we will look at how to consume servers using existing software, such as Visual Studio Code (VS Code) or Claude Desktop. When we say consume, what we mean is installing servers, configuring them, and then using them to run tools or interact with the server in some way.

In this chapter, you will learn how to do the following:

  • Understand how to consume servers using existing tools
  • Install and configure servers in VS Code
  • Work with the mcp.json file for server management
  • Manage secrets and configuration for servers
  • Use VS Code to test and interact with servers
  • Apply security best practices when consuming servers

The chapter covers the following topics:

  • Consuming with hosts such as Claude Desktop and VS Code
  • Installation process
  • Adding a server
  • Local and global install
  • Tips and tricks
  • Security aspects
  • Suggestion for servers

Consuming with hosts such as Claude Desktop and VS Code

Section titled “Consuming with hosts such as Claude Desktop and VS Code”

Consuming servers, okay, what does that mean? So to use an MCP server and its features, you need a way to interact with it. You’ve seen in Chapter 7 how to create a server and how to write a client that can interact with it. That’s a perfectly valid way to consume a server, but it requires you to write code.

Another approach is to use existing software such as Claude Desktop or VS Code. These tools are designed to work with MCP servers, and they also provide a large language model that ensures that you can interact with the server in a more user-friendly way via prompts.

We think of these two pieces of software as hosts, as they have a built-in MCP client, but they also use configuration files to keep track of the servers that are installed, the tools that are available, and so on.

How do they work? Well, they work in the following way:

  • Initiate a connection to the MCP server through a selected transport type, such as STDIO, SSE, or Streamable HTTP
  • Provide a user interface to interact with the server and let you type prompts, interact with tools, configuration, and more
  • Use configuration files to keep track of installed servers, available tools, and other settings

Here’s an example of the user interface in VS Code, which is representative of how these hosts work:

Figure 8.1 – VS Code interface

Figure 8.1 – VS Code interface

In the preceding figure, you can see the following:

  • A list of tools currently available via servers that are installed
  • A chat interface where you can type prompts

Let’s talk about specific hosts next and their features.

VS Code, together with GitHub Copilot, has extensive support for MCP servers. There are a variety of features that help you to install, configure, and secure servers. It supports use cases such as trying out servers you are building, as well as turning VS Code into an agentic app that can run tools through your prompts.

Here’s a list of features that VS Code provides for MCP servers:

  • Installing servers: VS Code lets you install servers both on a global level and on a workspace level. It supports the three transport types: STDIO, SSE, and Streamable HTTP.
  • Managing tools: You can enable and disable tools for a server, which is useful to ensure that the client has the context it needs.
  • Interacting with features: In addition to tools, it also supports features such as user prompts and resources.
  • Managing servers: You can add and remove servers and configure them.
  • Sampling: It supports sampling, which means that when a server sends a sample request, you can interact with it and tweak the request before sending back a response.
  • Elicitations: It also supports elicitation requests, which are scenarios when the server needs more information from the user to proceed with a request.
  • Logging and debugging: There’s also support for logging and debugging, which is useful when you are developing servers or clients.

Additional features are being made available all the time, and you’re recommended to use VS Code Insiders if you want to try these features as early as possible, as they’re shipped there first.

You can also use Claude Desktop to consume MCP servers. Head over to the download page (https://claude.ai/download) to install a client for your operating system. Just like VS Code, it provides a user interface and a whole set of features to interact with MCP servers.

Claude does a lot more than just work with MCP servers; it’s a fully-fledged AI assistant and is perhaps best compared with similar products such as ChatGPT or Copilot. For a full set of features, head over to this page: https://claude.ai/login?returnTo=%2F%3F#features.

To install servers, there’s a central concept for both Claude and VS Code, namely, the mcp.json file. This file is your main configuration file where you add information on where the servers are and additional configuration needed. In fact, this JSON file acts like a manifest file for what servers are installed. The act of installing a file means adding an entry to this file. Here’s an example of an mcp.json file:

{
"inputs": [
],
"servers": {
"docs": {
"type": "http",
"url": "https://learn.microsoft.com/api/mcp"
}
}
}

(1) to quickly copy code into your coding environment, or click the Explain button

(2) to get the AI assistant to explain a block of code to you.

![A white background with a black text

AI-generated content may be incorrect.](https://static.packt-cdn.com/products/9781806103232/graphics/Images/image_%282%29.png)

A white background with a black text AI-generated content may be incorrect.

In this file, we have a servers attribute with one server entry to https://learn.microsoft.com/api/mcp; this MCP server is now considered installed.

The full installation process for installing and running a feature on a server looks like so:

  1. Install a server by adding an entry mcp.json file in the servers attribute.
  2. Start the server.
  3. Use the server by typing a prompt matching a tool in the server.

We’ll explore such a scenario later in this chapter, but now you have a mile-high understanding of it. Let’s go into more depth on the mcp.json file.

The mcp.json file has two primary attributes:

  • inputs: This is used for defining placeholders for sensitive information, such as API keys or tokens. The idea is that you define that you want an input prompt to appear, and the answer should be stored in a variable that you can later refer to. Here’s an example of this:
    [
    {
    "id": "my_api_key",
    "description": "The API key that my MCP server needs",
    "type": "promptString",
    "password": true
    }
    ]

By the preceding definition, the user interface in VS Code will start an input prompt asking you to fill in this information. This then needs to be paired with a server entry, like so:

"my_mcp_server": {
"type": "http",
"url": "http://localhost:8000/mcp",
"headers": {
"Authorization": "Bearer ${my_api_key}"
}
}

Note how my_api_key is now passed in as a header property so that every time we call "http://localhost:8000/mcp", it will also pass the API key, ensuring that we can access our MCP server securely. Setting things up this way ensures that secrets stay out of mcp.json.

  • servers: This property takes a JSON object with server entries. What you need to know is that these entries look different depending on which transport is being used by the server. Let’s show examples for each transport type:
    • Using Streamable HTTP:
      "my_mcp_server": {
      "type": "http",
      "url": "http://localhost:8000/mcp"
      }
    In this case, it’s using Streamable HTTP; we can see that as the type value is http and a url value is specified. Let’s look at SSE next.
    • SSE:
      "my_mcp_server": {
      "type": "sse",
      "url": "http://localhost:8000/sse"
      }
    SSE, just like Streamable HTTP, is a transport meant for servers that are accessed remotely. Therefore, a url value is used in both cases to point out where these servers live.
    • STDIO:
      "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
      }
    STDIO, or standard I/O, needs to specify a command and args property as it needs to point out how to start the server in question. It’s not needed for SSE or Streamable HTTP, as these servers live remotely.

You’ve already seen in the previous section how various servers can be added, but let’s go through the motions of adding and using a server. Let’s use Playwright, an end-to-end (E2E) testing framework, as an example. To install it as an MCP server, what you usually do for any server is to locate its GitHub repo and see what its installation instructions are. For Playwright, its repository is here: https://github.com/microsoft/playwright-mcp.

There are quite a lot of instructions as this server offers a lot of features, but let’s grab the installation instructions from its Getting started section, which looks like so:

"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest"
]
}

Here, we see how it’s clearly a STDIO type server as its command and args properties are populated.

Let’s install this via VS Code. By doing so, we have a couple of different options on how to install it:

  • Add the entry directly to an mcp.json file.
  • Use a user interface, either with the Add Server button that’s present when you view the mcp.json file or by running the MCP: Add Server command from the command palette. In both cases, it will trigger a user interface asking you to decide on what transport to use, and either url or command and args information, depending on the chosen transport.

As an example, let’s click Add Server; you should be presented with the following interface:

Figure 8.2 – Installing the server

Figure 8.2 – Installing the server

As you can see, there are numerous options for installing a server: different transports, some also from different package managers, and even Docker.

In fact, if you choose the Browse MCP Servers… option, it will take you to a list of vetted MCP servers (https://code.visualstudio.com/insider/mcp) and let you choose a server from there.

We have the complete instructions for working with Playwright from its GitHub repo, but let’s install from this list of servers by selecting to install it like so, clicking Install Playwright:

Figure 8.3 – Install Playwright

Figure 8.3 – Install Playwright

Now, you should see a dialog opening in your VS Code giving you more information on the server, along with installation instructions. We had previously located the installation information by going to its GitHub repo, but this is also a great way to do it.

Okay, so it seems the answer is to either manually copy-paste what you need in mcp.json or use one of the many options in VS Code.

Now, you’ve added the server, so your mcp.json looks similar to the following JSON (note how Playwright is added):

{
"servers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest"
]
}
},
"inputs": []
}

It’s now time to see how the user interface supports us. One thing we can do is select Extensions; we should see our list of installed servers like so:

Figure 8.4 – Installed servers

Figure 8.4 – Installed servers

From this view, we can click the cog wheel on a server to interact with it:

Figure 8.5 – Interacting with the server

Figure 8.5 – Interacting with the server

As you can see, there are multiple options, from starting the server to seeing its logs, and even JSON configuration. You can take these actions from within the mcp.json file as well.

Let’s start the server, and now let’s turn to the chat interface we have from installing GitHub Copilot. Make sure the agent is selected in the droplist and then type the following prompt:

Navigate to https://tfl.gov.uk/. I want to go from Paddington to Heathrow, show me how to get there by underground, important use playwright tool

Sometimes, VS Code is a bit unwilling to use a tool, so it’s worth spending some time on the prompt to ensure it does use it. I’ve added important use playwright tool to ensure the tool is triggered.

You should see the following in the chat interface:

Figure 8.6 – Using the tool

Figure 8.6 – Using the tool

This shows a tool being triggered, and you being asked to allow the tool to run as part of this. You can see how the URL is parsed out from your prompt and matched as the input to the Playwright tool. This should trigger a whole series of tool calls as Playwright will go through the website, locate the input field, and try to complete the mission set out by the prompt.

You might need to restart the chat sometimes, but once it works as it should, you should see something like the following figure, indicating that Playwright has started to navigate the site properly and is trying to get you from Paddington to Heathrow:

Figure 8.7 – Playwright query

Figure 8.7 – Playwright query

Once it’s done, you can interact with it in various ways to get what you need and even ask it to generate the Playwright tests from this interaction, which is where the real value lies.

So far, we’ve installed servers in .vscode/mcp.json, which means they are installed into this workspace only. You can install servers globally on your machine as well. To choose that instead, let’s use MCP: Add Server from the command palette. At the last step, choose Global, and it will create an mcp.json file in (Settings)/User/mcp/json, which means it has added the server entry to the user setting rather than this specific workspace instance. That means that if you open up another instance of VS Code, you will not need to install this server again.

Here’s what the user-level mcp.json file looks like after a server has been globally installed:

{
"servers": {
"my-mcp-server-6801ea17": {
"url": "https://learn.microsoft.com/api/mcp",
"type": "http"
}
},
"inputs": []
}

As you can see, there’s no difference in how it’s installed in the actual mcp.json file, but the difference is in where the mcp.json file is located. The general rule of thumb is, if it’s a server you use often, install it globally; if not, install it in the workspace at .vscode/mcp.json.

So far, we’ve gone through the basics, but what else is there to know? Well, there are quite a few different settings. A complete listing of features can be found at this docs page: https://code.visualstudio.com/docs/copilot/chat/mcp-servers.

As a developer, knowing how to debug is a critical skill, so let’s show how to do that. Currently, Node.js debugging is supported, according to the documentation (https://code.visualstudio.com/docs/copilot/customization/mcp-servers#_debug-an-mcp-server):

"server-ts": {
"command": "node",
"args": ["08 - consuming servers/code/build/index.js"],
"dev": {
"watch": "08 - consuming servers/code/build/**/*.js",
"debug": { "type": "node" }
}
}

According to the preceding configuration, what you need to do is this:

  1. Set up your command and args properties to instruct how to run the server.

  2. Add dev with two different attributes: watch, which is a global pattern (GLOB) that looks at your JavaScript files for changes, and debug, which is where you specify which process is debugging it. In this case, it’s Node. Once it’s set up and the server is running, there should be a gray debug text just above. Make sure you’ve added a breakpoint in suitable places, such as starting the server, running a tool, and so on. Here’s how you can test different scenarios:

    1. Testing startup: Here, we’ve just added a breakpoint to our startup code, and all we need to do is start the server from mcp.json. You should see how the breakpoint is hit, like so: Figure 8.8 – Breakpoint startup Figure 8.8 – Breakpoint startup
  3. Testing tools: A good way to test the tools is to run the inspector in CLI mode. Here’s a command for testing a tool, add, with input parameters, a and b. Adopt this command to match the operations and parameters on your server:

    npx @modelcontextprotocol/inspector --cli node ./build/index.js --method tools/call --tool-name add --tool-arg a=1 --tool-arg b=2

You should see a response directly in the terminal that looks similar to the following:

{
"content": [
{
"type": "text",
"text": "3"
}
]
}

Sometimes, you will see an error indication on the tools icon in the chat area. If that happens, open the Output section in your terminal area, and you will see what the problem is. This area is a good place to inspect generally, as you will see every interaction between VS Code and your server, such as when it starts up and stops servers, but also when it initializes, lists tools, and more.

When we ran the debugger and it connected to the server, we got all this information written to Output:

2025-08-03 19:18:56.856 [info] Connection state: Starting
2025-08-03 19:18:56.857 [info] Connection state: Running
2025-08-03 19:18:56.857 [info] [editor -> server] {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{"roots":{"listChanged":true},"sampling":{},"elicitation":{}},"clientInfo":{"name":"Visual Studio Code - Insiders","version":"1.103.0-insider"}}}
2025-08-03 19:18:56.888 [warning] [server stderr] Debugger listening on ws://127.0.0.1:9230/7b07fce3-e6cc-46c7-a0b8-7b782fbe853a
2025-08-03 19:18:56.888 [warning] [server stderr] For help, see: https://nodejs.org/en/docs/inspector
2025-08-03 19:18:57.052 [warning] [server stderr] Debugger attached.
2025-08-03 19:19:01.960 [info] Waiting for server to respond to \`initialize\` request...
2025-08-03 19:19:06.960 [info] Waiting for server to respond to \`initialize\` request...
2025-08-03 19:19:10.858 [warning] Failed to parse message: "Starting MCP server...\n"
2025-08-03 19:19:10.874 [info] [server -> editor] {"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{"listChanged":true}},"serverInfo":{"name":"demo-server","version":"1.0.0"}},"jsonrpc":"2.0","id":1}
2025-08-03 19:19:10.874 [info] [editor -> server] {"method":"notifications/initialized","jsonrpc":"2.0"}
2025-08-03 19:19:10.874 [info] [editor -> server] {"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}
2025-08-03 19:19:10.891 [info] [server -> editor] {"result":{"tools":[{"name":"add","title":"Addition Tool","description":"Add two numbers","inputSchema":{"type":"object","properties":{"a":{"type":"number"},"b":{"type":"number"}},"required":["a","b"],"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}}]},"jsonrpc":"2.0","id":2}
2025-08-03 19:19:10.891 [info] Discovered 1 tools
2025-08-03 19:26:34.115 [warning] [server stderr] Debugger ending on ws://127.0.0.1:9230/7b07fce3-e6cc-46c7-a0b8-7b782fbe853a
2025-08-03 19:26:34.115 [warning] [server stderr] For help, see: https://nodejs.org/en/docs/inspector

Let’s highlight some interesting parts from the preceding response:

  • Editor handshakes with server: Here, the editor sends information to the server on what features/capabilities it supports. It says to the server that it supports roots, sampling, and elicitation:
    2025-08-03 19:18:56.857 [info] [editor -> server] {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{"roots":{"listChanged":true},"sampling":{},"elicitation":{}},"clientInfo":{"name":"Visual Studio Code - Insiders","version":"1.103.0-insider"}}}
  • Server responds to editor handshake: Here, the response comes back to say that tools are supported:
    2025-08-03 19:19:10.874 [info] [server -> editor] {"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{"listChanged":true}},"serverInfo":{"name":"demo-server","version":"1.0.0"}},"jsonrpc":"2.0","id":1}
  • Server sends initialized notification: The last step in the handshake is sending the initialized notification. This is something the client sends to the server to say it’s ready to exchange data. In this case, our client is VS Code:
    2025-08-03 19:19:10.874 [info] [editor -> server] {"method":"notifications/initialized","jsonrpc":"2.0"}
  • Tell me about your tools: Now the client asks the server for its tools:
    2025-08-03 19:19:10.874 [info] [editor -> server] {"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}
  • Server responds to tools request: Lastly, the server responds to a request to list its tools with the following:
    2025-08-03 19:19:10.891 [info] [server -> editor] {"result":{"tools":[{"name":"add","title":"Addition Tool","description":"Add two numbers","inputSchema":{"type":"object","properties":{"a":{"type":"number"},"b":{"type":"number"}},"required":["a","b"],"additional Properties":false,"$schema":"http://json-schema.org/draft-07/schema#"}}]},"jsonrpc":"2.0","id":2}

Tool management is an important aspect of using VS Code. There are some interesting scenarios around tools where your editor helps:

  • Selecting and deselecting tools: When you add servers, it might add a lot of tools at once. For both scenarios, where you use your editor as an agentic tool and also where you want to ensure the correct tool is called, you can choose which tools are active. You can make this selection by clicking the tools icon in the chat, which will bring up a user interface of all tools. Select/deselect the tools you want to have active or inactivate.
  • Run a specific tool: Generally, when you want to run tools, you try to type a prompt that matches a specific tool’s description as much as possible. If you want to make sure that the correct tool is chosen, you can prefix it with #, which will identify that specific tool. For example, to run a tool called add, you can craft a prompt like so:
    #add 2 and 7
  • Managing the number of tools: Some models have limitations on how many tools they can accept. To address this, there’s a setting called github.copilot.chat.virtualTools.enabled, which will analyze the prompt and only submit the tools that match the prompt. This is a great way to avoid any errors as a result of using too many prompts. Make sure you’re on the latest version of VS Code Insider. This feature is in active development and may change over time.
  • Handle tool approval: When VS Code decides it wants to run a tool, it displays it as a query asking you to click Continue. At this point, you can choose to allow it only for this prompt session, for this workspace, or to always allow. Here’s how it works:
    1. Type the following prompt:
      #add 2 and 7
    This makes VS Code ask you to click Continue. Now, select from the dropdown to allow for this workspace. Let’s run it again.
  1. Type the following prompt:
    #add 2 and 9

This ran the tool without asking for my consent, as I had previously given it permission to run in this workspace. To undo this consent, I can run Chat: Reset Tool Confirmations from the command palette.

There are a lot of settings being added all the time to both Copilot and VS Code. Make sure you’re in VS Code Insiders, type MCP in the command palette, and you will see many dedicated MCP settings:

Figure 8.9 – MCP commands

Figure 8.9 – MCP commands

As you can see, there are quite a lot of commands available. Try typing Copilot as well, as it’s used in conjunction with MCP. This is a changing area, though, but if you are developing MCP servers, it’s part of your job to leverage your editor to the best of your ability.

Security is a huge topic, but let’s discuss it in the context of using an editor. There are things you can do generally to stay safer, so let’s try to summarize a good list of practices:

  • Keep secrets out of configuration: Here’s how you can do that by specifying the configuration in the mcp.json file:
    {
    "mcp": {
    "inputs": [
    {
    "type": "promptString",
    "id": "my-key",
    "description": "Token for my API",
    "password": true
    }
    ],
    "servers": {
    "my-server": {
    "type": "http",
    "url": "https://my-secure-api/mcp",
    "headers" : {
    "Authorization": "Bearer ${input:my-key}"
    }
    }
    }
    }
    }

By using the inputs element, you can ensure that secrets are kept out of the configuration file. How it works is that when the server is started, the user interface will prompt you to fill in the value for my-key, and it will be stored securely. The value can then be referenced in the server entry by using ${input:my-key}. For every request to https://my-secure-api/mcp, the Authorization header will be added with the value you provided.

  • Tool running access: It’s recommended to disallow continuous access for a tool running in a workspace. Prefer giving it access each time it’s asked for. It also gives you the chance to check the parsed input.
  • Restrict what a server can do: There are ways to restrict what a server can access. For example, there’s an MCP server for file access. You should restrict it to one folder at most or folders where you’re sure it can’t do any harm.
  • Use trusted servers: GitHub recently released a registry of vetted MCP servers. Using the latest version of VS Code Insiders, you can type @mcp, and it will show a list of MCP servers that you can install. You can access that same list by choosing the MCP: Add Server command and then selecting Browse MCP Servers. Your list of servers should look similar to this figure:

Figure 8.10 – MCP registry

Figure 8.10 – MCP registry

In general, make sure the author behind a server is a reputable source (e.g., Stripe is behind the Stripe MCP server, and so on). Even then, resort to code scanning tools and keep track of the latest security news; breaches happen all the time. The same registry can also be found via this link (https://code.visualstudio.com/insider/mcp), but I prefer using the built-in experience in VS Code. Also, check out the GitHub repo for servers, as that allows you to read more on each server via their README files (https://github.com/modelcontextprotocol/servers).

So what servers are recommended? Well, it depends on your needs, but I would personally use the following:

There are many more, but start with these and see what fits your scenario.

In this chapter, we went through how to consume an MCP server, both the ones you create and external ones. Additionally, we discussed how to manage servers once installed, their configuration, tool usage, and more.

Finally, we provided some tips on security practices. This should be seen as a bare minimum set of practices, and you should do more.

In the next chapter, we’ll cover sampling, an advanced topic but very useful when the server needs to delegate work to you as the user.

Install a server of your choice, and try it out via a prompt. Try installing a server from here: https://code.visualstudio.com/insider/mcp.

How do you install an MCP server?

  • A: You can install it in the same way you install extensions in VS Code.
  • B: You run mcp install <server name> in the terminal.
  • C: Servers are installed by adding text entries to mcp.json. You also need to specify how to start it or where the server resides.

You can access the solution at https://github.com/PacktPublishing/Learn-Model-Context-Protocol-with-Python/blob/main/Chapter08/solutions/solution-quiz.md.