Blog / AI agents

What Is an MCP Server? A Working Example with Web Data

An MCP server is a program that offers an AI application tools, resources and prompts through the Model Context Protocol, an open standard built on JSON-RPC 2.0. The application connects as a client, asks the server what it offers, and lets the model call those tools. A server runs either as a local subprocess (stdio) or as an HTTP endpoint (Streamable HTTP). Below is a real one: the three tools Perceptlayer's server lists, the messages that go over the wire, and what each call costs.

What is an MCP server, in the specification's terms?

The Model Context Protocol defines three roles. A host is the AI application, such as Claude Desktop or an IDE. A client is the connector inside the host. A server is the service that provides context and capabilities (MCP specification, 2026). Every message between client and server is a JSON-RPC 2.0 request, response or notification.

So an MCP server is the far end of that connection. It doesn't run the model and it doesn't decide when to call anything. It describes what it can do, in a format every MCP client understands, and it does the work when the client asks. The spec compares this to the Language Server Protocol: one protocol, so each tool doesn't need a custom integration per AI app.

That's the practical difference from writing your own function definitions for one model's tool-calling API. A function you define lives in your code and works with that one integration. An MCP server works with any client that speaks the protocol. MCP vs Function Calling for Live Web Data in Agents compares the two in more depth.

What can an MCP server offer: tools, resources and prompts?

A server can offer any of three primitives, and they differ by who controls them: the model decides when to call a tool, the application decides which resources to attach, and the user picks a prompt. The server overview in the specification (2026) sets them out as a control hierarchy:

Primitive Controlled by What it is Example
Tools The model Functions the model can call to act or fetch information An API request, writing a file
Resources The application Data the client attaches as context File contents, git history
Prompts The user Templates the user picks A slash command

Most servers people build for agents are tool servers, because tools are what let a model fetch data it doesn't have. A server doesn't have to offer all three. Perceptlayer's server offers tools only, and says so when a client asks: its declared capabilities are {"tools": {"listChanged": false}}.

How does a client talk to a server: stdio or Streamable HTTP?

The specification defines two standard transports, stdio and Streamable HTTP, and the JSON-RPC messages are the same on both (MCP transports, 2026). What changes is where the server runs, how a message gets there and who can reach it. A local tool usually ships as a stdio server; a hosted service usually ships as Streamable HTTP.

stdio Streamable HTTP
Where the server runs A subprocess the client launches An independent process, local or remote
How messages travel Newline-delimited JSON on stdin and stdout Each message is an HTTP POST to one MCP endpoint
Replies One message per line on stdout A JSON object or an SSE stream for that request
Auth The local user's environment HTTP headers; the spec says servers should authenticate every connection
Typical use Local files, local tools Hosted APIs shared by many clients

With stdio the server writes only valid MCP messages to stdout and may log to stderr (stdio transport, 2026). With Streamable HTTP the server must validate the Origin header to prevent DNS rebinding, and each POST mirrors the protocol version and method into the MCP-Protocol-Version and Mcp-Method headers (Streamable HTTP transport, 2026). Remote MCP Server: Streamable HTTP vs Local stdio goes through the remote case in detail.

What does a real MCP server look like on the wire?

A worked example makes the definition concrete. Perceptlayer's server is at https://perceptlayer.com/mcp, over Streamable HTTP, and it fronts a catalogue of 707 websites and 3,834 endpoints. Listing 3,836 tools would flood a model's context, so the server lists three and lets the model search. The requests below were run against a local build of the server's code, not the live endpoint, and the responses are trimmed with ….

Step 1: list the tools

The client sends tools/list. Listing the catalogue is public, so this needs no key.

curl -X POST https://perceptlayer.com/mcp \
  -H "Content-Type: application/json" \
  -H "MCP-Protocol-Version: 2026-07-28" \
  -H "Mcp-Method: tools/list" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}'

The result holds three tool definitions, each with a name, a description and a JSON Schema inputSchema:

{"jsonrpc":"2.0","id":1,"result":{"resultType":"complete","tools":[{"name":"search_endpoints","title":"Search data endpoints","description":"Find Perceptlayer endpoints for a website or kind of data. The catalogue has 3836 endpoints across 704 sources, so search before calling. …"}, … ],"ttlMs":3600000,"cacheScope":"public", …}}
Tool Input What it returns Credits
search_endpoints query, optional vertical and limit Matching endpoint IDs, credits and required parameters 0
get_endpoint endpoint Every parameter with its type, limits and allowed values 0
call_endpoint endpoint, params The endpoint's JSON response, plus credits used and remaining The endpoint's credits, on success only

Step 2: search the catalogue

The model calls search_endpoints with a few words. Note the extra Mcp-Name header, which the spec requires on every tools/call.

curl -X POST https://perceptlayer.com/mcp \
  -H "Content-Type: application/json" \
  -H "MCP-Protocol-Version: 2026-07-28" \
  -H "Mcp-Method: tools/call" \
  -H "Mcp-Name: search_endpoints" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"search_endpoints","arguments":{"query":"google search results","limit":3},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}'

The tool result is text content holding JSON:

{"total_matches":346,"results":[{"endpoint":"google-search.google-ai-mode-search", …},{"endpoint":"google-search.search","name":"Google Search: Search","method":"GET","credits":1,"tier":"standard","required_params":["query"]}, …],"hint":"More matches exist; refine the query or raise limit."}

The model now knows google-search.search needs a query and costs 1 credit. If it needs more, get_endpoint returns the full parameter list, also free.

Step 3: call the endpoint

call_endpoint runs the endpoint with the caller's key, sent as Authorization: Bearer in the server config. Sent without a key, as in our local run, the server answers with a tool error rather than a protocol error, so the model can read it:

{"jsonrpc":"2.0","id":4,"result":{"resultType":"complete","content":[{"type":"text","text":"Error invalid_api_key: Missing, unknown or revoked API key. No API key was sent: add 'Authorization: Bearer <your key>' to this MCP server's configuration. …"}],"isError":true, …}}

With a valid key, the first content block is the endpoint's JSON and the second reports the spend, in the form Credits used: 1. Credits remaining: …. The JSON is the same as a direct call to GET /v1/google-search/search. This is the recorded response for best restaurants in Berlin, trimmed:

{
  "organic_results": [
    {
      "position": 1,
      "title": "The Best Restaurants in Berlin - Food Guide & Map",
      "link": "https://andershusa.com/best-restaurants-berlin-germany-guide/",
      …
    },
    …
  ],
  "related_questions": [
    {
      "question": "What is the coolest restaurant in Berlin?",
      …
    }
  ],
  …
}

What does each MCP call cost?

Only one of the four requests above spends anything. tools/list, search_endpoints and get_endpoint read the catalogue and cost 0 credits. call_endpoint costs the endpoint's credits, and only on success; failed calls return X-Credits-Used: 0 over HTTP and the same zero over MCP.

So one answered question costs 0 + 0 + 0 + 1 = 1 credit. An agent that answers 500 questions a day with one search each spends 500 × 1 credit = 500 credits a day, or 15,000 credits over 30 days. That's more than the 100 free credits on signup, and within the Build pack's 50,000. See pricing for what credits cost, and Scheduled AI Agent Runs: Budgeting Credits per Run for capping it.

Requests run under the account's rate limit: 1 request a second on a free account, at least 5 a second on a paying one. A 429 carries Retry-After, which the tool error passes on to the model. The rate limits docs list the rest.

How do you connect a client to an MCP server?

You give the client the server's URL and transport, plus any auth header, and the client handles the protocol from there: it lists the tools, passes their definitions to the model and sends the calls. Most clients take this as a config entry or one command. For Claude Code, with your key in API_KEY:

claude mcp add --transport http perceptlayer https://perceptlayer.com/mcp --header "Authorization: Bearer $API_KEY"

We didn't run this command for this post. For Claude Desktop and Cursor, How to Add an MCP Server to Claude Desktop and Cursor has the config files, and the AI agents (MCP) docs cover other clients. If your client lists too many tools from too many servers, MCP Server Too Many Tools shows how to keep context small.

To see what the model gets back before you connect anything, run a search in the playground on the Google Search API page, or get a free API key and send the requests above.

APIs in this post

Frequently asked questions

Is an MCP server the same as an API?

No. An MCP server often wraps an API, but it adds a layer a model can use: a self-describing tool list with JSON Schema inputs, discovered at runtime over JSON-RPC. A plain REST API has endpoints a developer reads about in docs. Perceptlayer offers both: the HTTP API at /v1/... paths and the MCP server, and call_endpoint returns the same JSON as the HTTP call.

Do I need to run an MCP server myself?

Not for a remote one. A Streamable HTTP server runs on someone else's infrastructure and your client connects to its URL. You run a server yourself when it needs local access, such as your files or a local database, which is what stdio is for, or when you're exposing your own API to agents.

Does listing an MCP server's tools cost credits?

No. On Perceptlayer's server, tools/list, search_endpoints and get_endpoint cost nothing and need no API key. Only call_endpoint spends credits, it spends the endpoint's listed amount (1 credit for nearly all endpoints), and only when the call succeeds. Every account gets 100 free credits after verifying an email address.

How does an MCP server authenticate requests?

The specification says Streamable HTTP servers should authenticate every connection and defines an authorization framework for HTTP transports. Perceptlayer's server takes your API key as Authorization: Bearer or X-API-Key, and only call_endpoint needs it. MCP Server Authentication: API Keys vs OAuth compares the two approaches.

What happens when an MCP tool call fails?

The server returns a tool result with isError: true and a message the model can act on, such as invalid_parameters, rate_limited with the seconds to wait, or insufficient_credits. A failed call costs nothing. MCP Tool Call Error Handling covers which errors an agent should retry and which it shouldn't.

  1. AI Agent Tools: What an Agent Needs for Web Data

    An agent tool is a name, a description, an input schema and a result. How search, lookup and fetch tools map to three MCP tools, two of them free.

  2. Remote MCP Server: Streamable HTTP vs Local stdio

    A remote MCP server runs over Streamable HTTP: one POST endpoint, auth headers, Origin checks, no sessions. Real responses, and when stdio fits better.

  3. MCP Server Too Many Tools: Keeping Agent Context Small

    One tool per endpoint for 1,659 endpoints is about 567,000 characters of schema. A 10-step checklist to keep an MCP server's tool list small.

Start with 100 free credits

No password to set. We email you a sign-in link, and your key works on every API.

No credit card. 100 free credits on signup.