MCP in Practice: Set Up, Secure and Choose MCP Servers

The Model Context Protocol (MCP) is an open standard for connecting AI applications to tools and data. An MCP server offers tools, resources and prompts. An AI application connects to it through an MCP client, and the model can then use what the server offers. Using MCP well comes down to three decisions: which servers to trust, what each one may touch, and how much of the model’s context its tools consume.

This guide follows the 2026-07-28 revision of the specification, the first since 2025-11-25, which made the protocol stateless. Older tutorials, including some on this site, describe the earlier connection handshake. The Claude Code commands below were run with Claude Code 2.1.326 on 17 November 2026.

How MCP works

The specification defines three roles that exchange JSON-RPC 2.0 messages. A host is the AI application, such as an IDE or chat app. A client is the connector inside the host. A server is the program that provides context and capabilities. The spec says MCP takes some inspiration from the Language Server Protocol, which standardized language support across editors.

Servers can offer three features:

  • Tools: functions the model can call, such as running a query or creating an issue.
  • Resources: context and data for the user or the model, such as files or records.
  • Prompts: templated messages and workflows that users can pick.

Clients can offer elicitation, which lets a server ask the user for more information. Optional extensions add features such as long-running tasks and interactive UI.

There are two standard transports. With stdio, the client launches the server as a subprocess and exchanges newline-delimited messages over standard input and output. With Streamable HTTP, each message is an HTTP POST to one endpoint, and replies come back as JSON or as a stream scoped to that request. The older HTTP+SSE transport is deprecated.

MCP started at Anthropic. Since 9 December 2025 it has been a founding project of the Linux Foundation’s Agentic AI Foundation, alongside Block’s goose and OpenAI’s AGENTS.md.

What changed in 2026-07-28

Area 2025-11-25 and earlier 2026-07-28
Connection initialize handshake; sessions via the Mcp-Session-Id header No handshake or sessions; every request carries its protocol version and client capabilities
Discovery Learned during the handshake Servers must implement server/discover
Server questions to the client Servers could send their own requests Servers return an “input required” result and the client retries the original request with the answers
Long-running work Experimental tasks in the core protocol Tasks moved to an official extension
Deprecated Roots, Sampling and Logging; HTTP+SSE; Dynamic Client Registration, in favor of Client ID Metadata Documents
Caching tools/list should return tools in a deterministic order; list results carry a freshness hint

The practical effect is that a request no longer depends on an earlier one on the same connection, which makes remote servers easier to scale behind load balancers. Servers that need state across calls return an explicit handle, such as a basket ID, and receive it back as a normal tool argument. The spec also defines a fallback for talking to servers that implement older revisions.

MCP, function calling, skills or a CLI?

MCP is not always the right tool. Use the table to pick the lightest option that does the job.

You need Best fit Why
One application calling your own API Native tool or function calling in that app No extra process, protocol or server to trust
The same integration in several AI apps An MCP server Build once; any MCP client can use it
Reusable instructions or a workflow, possibly with scripts A skill Claude Code skills are folders with a SKILL.md file; only their descriptions load until a skill is used, and they follow the Agent Skills open standard
An agent that already has a sandboxed shell and a well-known CLI such as git The CLI Nothing new to install, and your sandbox rules already apply

Tool definitions are not free. Anthropic’s engineering team notes that when every definition loads up front, “tool definitions overload the context window,” and that intermediate results passing through the model cost more tokens. In one example in that post, presenting MCP servers as code APIs that the agent calls from a sandbox cut usage “from 150,000 tokens to 2,000 tokens.” That approach needs a secure execution environment, but the lesson applies to everyone: connect fewer servers, and prefer servers with fewer, better tools.

Set up servers safely

A server is software you run, or a service you hand a token to. Treat adding one like adding a dependency with credentials. Before you connect a server:

  1. Check the source. Prefer the vendor’s official server or an actively maintained project whose owner you can identify. The MCP Registry, still in preview, verifies namespaces through GitHub, DNS or HTTP challenges, but it leaves security scanning to package registries and downstream marketplaces. A registry listing is not a security review.
  2. Pin the version. npx -y some-server installs whatever is newest each time it starts. npx -y some-server@2.3.0 does not.
  3. Grant the least access. Pass only the directory, project or account the job needs, and use read-only tokens where they exist.
  4. Keep secrets out of config files. Reference environment variables instead of pasting tokens.
  5. Choose the scope deliberately. Shared project configuration ends up in version control and on teammates’ machines.

In Claude Code, the commands look like this. The first adds a local filesystem server, pinned to one version and limited to ./docs. The second adds a remote server whose token comes from your shell:

claude mcp add --scope project --transport stdio docs-fs \
  -- npx -y @modelcontextprotocol/server-filesystem@2.3.0 ./docs

claude mcp add --scope project --transport http example-api \
  https://mcp.example.com/mcp \
  --header 'Authorization: Bearer ${EXAMPLE_API_TOKEN}'

Run in an empty test project, they produced this .mcp.json:

{
  "mcpServers": {
    "docs-fs": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem@2.3.0", "./docs"],
      "env": {}
    },
    "example-api": {
      "type": "http",
      "url": "https://mcp.example.com/mcp",
      "headers": { "Authorization": "Bearer ${EXAMPLE_API_TOKEN}" }
    }
  }
}

The single quotes keep ${EXAMPLE_API_TOKEN} literal, and Claude Code expands it when it loads the file, so the token never lands in the repository. The -- separates Claude Code’s options from the server command. Use the JSON formatter if a hand-edited config stops loading.

Scope matters for safety. Claude Code stores local (the default) and user servers in ~/.claude.json, and project servers in .mcp.json at the project root. Claude Code asks for approval before using project servers in interactive sessions, but its documentation notes that claude -p runs and Agent SDK sessions load them without asking. In CI, start Claude Code with --strict-mcp-config and list the servers you want with --mcp-config, so a pull request that edits .mcp.json cannot add a server to your pipeline.

Watch the context budget too. Claude Code warns when an MCP tool returns more than 10,000 tokens and caps output at 25,000 tokens by default (MAX_MCP_OUTPUT_TOKENS changes it). Its tool search, on by default for current models, loads only tool names and server instructions at session start.

MCP security risks and controls

The specification is candid about the limits: tools “represent arbitrary code execution,” hosts “must obtain explicit user consent before invoking any tool,” and MCP “cannot enforce these security principles at the protocol level.” Enforcement is up to clients, servers and you. The security best practices and the authorization spec list the main attacks:

Risk What happens Controls
Tool poisoning Hidden instructions in a tool description steer the model. Invariant Labs described this in April 2025, along with “rug pulls” that change a tool after approval Treat descriptions and annotations as untrusted unless the server is trusted; pin versions; review tool lists after updates
Injection through results A fetched web page or issue contains instructions Show tool inputs before calls; require approval for actions that send data out; limit network egress
Malicious local server A config entry runs arbitrary commands with your privileges Clients must show the exact command before one-click installs; run local servers in a sandbox
Token passthrough A server forwards tokens that were not issued for it Servers must validate the token audience and “MUST NOT accept or transit any other tokens”
Confused deputy A proxy server with a static client ID skips user consent Proxy servers must keep per-client consent and match redirect URIs exactly
SSRF during OAuth discovery A malicious server points the client at internal URLs such as 169.254.169.254 Require HTTPS, block private IP ranges, route discovery through an egress proxy
DNS rebinding A website talks to an HTTP server on your machine Validate the Origin header, bind to 127.0.0.1, require authentication, or use stdio
State handle hijacking A guessed handle exposes another user’s state Random, expiring handles bound to the authenticated user
Over-broad scopes A stolen token opens everything Minimal initial scopes and step-up authorization; no wildcard scopes

The tools section adds the human side: there “SHOULD always be a human in the loop with the ability to deny tool invocations.” Two servers that are each fine can be dangerous together. A web-fetch server plus a server with access to private data gives one session untrusted input, private data and an outbound channel, which is the lethal trifecta described in the AI agent security guide.

How to choose an MCP server

Run every candidate through the same checks:

  • Maintainer: an official vendor server, or a project with a known owner, recent releases and an issue tracker that gets answers.
  • Access needed: which tokens, scopes, paths and network destinations the server needs, and whether it offers a read-only mode.
  • Tool list: read the names and descriptions. Words such as “send,” “delete” or “execute” deserve a closer look.
  • Transport: stdio for local servers; Streamable HTTP for remote ones. Ask before adopting a server that only offers HTTP+SSE.
  • Spec version: whether it supports 2026-07-28 or relies on the backward-compatibility fallback.
  • Context cost: how many tools it adds, and whether it paginates or truncates large results.
  • First test: one small, read-only action in a throwaway project, as the connect-an-AI-tool checklist suggests.

FindPicked’s MCP server directory groups thousands of servers and related projects by category from a dated snapshot. Inclusion there is not a functional test or an endorsement, so use it to find candidates and then apply the checks above. The skills directory does the same for reusable skills. If skills are new to you, start with what Claude Code skills are and how to write one.

If you build your own server

  • Design tools around tasks, not endpoints. Anthropic’s guide to writing tools for agents warns against tools that “merely wrap” API endpoints and recommends namespaced names, meaningful identifiers and concise responses.
  • Report recoverable failures as tool errors. The spec separates protocol errors from tool execution errors returned with isError: true, which the model can read and correct.
  • Bound your output. Paginate, filter or truncate large results.
  • Keep state explicit. Return handles, check authorization on every call and state when handles expire.
  • Log to stderr or OpenTelemetry. With Logging deprecated, the changelog points stdio servers to stderr, and a stdio server must not write anything but MCP messages to stdout.
  • Bind to localhost and check Origin if you serve HTTP locally.

Common mistakes

  • Installing servers from a list without reading their tool definitions.
  • Running unpinned npx -y commands that change silently.
  • Committing tokens in .mcp.json instead of using ${VAR} references.
  • Exposing a local HTTP server on 0.0.0.0 without authentication.
  • Connecting a browsing server and a private-data server in one session without approval gates.
  • Enabling dozens of servers and running out of context before the task starts.
  • Following tutorials that present the initialize handshake or HTTP+SSE as current.

FindPicked guides on MCP

These articles cover single topics in more depth. Articles published before 28 July 2026 describe the earlier protocol revision, so check transport and handshake details against the changelog.

Related reading: AI Agent Security and Guardrails for prompt injection and sandboxing, and Context Engineering and Memory for AI Agents for keeping tool output from flooding the context window.

Frequently Asked Questions

Is MCP only for Claude?

No. MCP is an open protocol, and since December 2025 it has been hosted by the Linux Foundation’s Agentic AI Foundation. Any application that implements an MCP client can use MCP servers, so check your own tool’s documentation for its supported transports and protocol versions.

What changed in MCP 2026-07-28?

The protocol became stateless. The initialize handshake and protocol sessions were removed, every request carries its own version and capabilities, and servers must answer server/discover. Roots, Sampling, Logging and the HTTP+SSE transport are deprecated, and tasks moved to an extension.

Are MCP servers safe to install?

A server is code you run or a service you give a token to, so it is as safe as its maintainer and the access you grant it. Pin versions, read the tool list, use least-privilege tokens, keep secrets in environment variables and approve actions that send data out.

Should I build an MCP server or a skill?

Build an MCP server when an AI app needs to reach an external system, such as an API or database. Write a skill when you want to package instructions or a repeatable workflow. Many setups use both: the skill describes the process and the server provides the access.