Pular para o conteúdo
← Back to Skalablog

Published article

How to Build a Model Context Protocol Server

ClaudeCursorAnthropic

The model context protocol is Anthropic open standard for connecting AI assistants to external data sources. You write or install an MCP server, plug it into a client such as Cursor or Claude Desktop, and the assistant calls your APIs, databases and services directly from the chat.

What Is the Model Context Protocol?

The model context protocol is an open standard that Anthropic announced and open-sourced on 25 November 2024 to connect AI assistants directly to data sources such as databases, APIs and files. Instead of writing custom integration code for every service, you plug in ready-made MCP servers and the assistant calls them during the conversation.

The protocol matters because it changes the direction of the work. Before it, connecting an assistant to PostgreSQL, Slack or Gmail meant downloading each vendor's SDK and coding the integration by hand, as Brazilian developer Erick Wendel demonstrated in earlier tutorials using Neo4j queries generated manually from a database schema.

With MCP, the tool describes itself: each function exposes a name, a description and a parameter schema. The assistant reads that description, fills in the arguments based on what the user asked, and invokes the tool. If a required parameter is missing, the client catches the validation error and the assistant can retry with corrected input.

The protocol distinguishes two building blocks. Tools execute actions, such as fetching talks from an API or sending a message. Resources provide extra context that helps the assistant reason about a task. The official documentation covers both concepts in detail.

Why MCP Reduces Hallucinations and Manual Coding

MCP reduces hallucinations by grounding answers in live data. When an assistant fetches the real status of a pull request or the actual list of talks from an API, it answers from the source rather than from training data that may be outdated or invented.

It also removes repetitive integration work. In the tutorial this article is based on, Erick Wendel had an API that exposes his talks, videos and articles through a GraphQL endpoint. He wanted an assistant to query it without writing a custom layer for every question type, so he wrapped the API in an MCP server and let the protocol handle the plumbing.

The same pattern scales to any service. A video tutorial by Gustavo Dev Doido on the Bootcamp do Dev Doido channel covers a similar workflow for developers studying stacks like the Crazystack Typescript course at crazystack.com.br, showing how Brazilian dev education has picked up the MCP approach quickly.

How the Demo Server Was Built

The example server exposes data from erickwendel.com: talks, videos and articles served by a public GraphQL API. Three steps turned that API into an MCP server, and each step can be reused for your own backend.

Generate an SDK from the GraphQL schema

A GraphQL code generator consumed the API's schema and produced a JavaScript client, so the server code never hits raw URLs or hand-writes queries. Selecting only the needed fields also keeps responses small, which matters when the payload travels through a model's context window.

Define tools with typed schemas

Using the TypeScript SDK for MCP with Node.js, each capability is registered as a tool: a command name such as get talks, a short description for the assistant, and a validation schema for parameters like title, language and limit. The project runs on Node.js 23, which executes TypeScript files natively without a transpiler. Support for running TypeScript directly arrived with Node.js 23 and Node.js 22.6 behind a flag, so version matters here.

Add automated tests with the Node.js test runner

The project's setup creates an MCP client inside the tests and calls each tool with the same arguments an assistant would send. This uses the built-in Node.js test runner, so no extra test framework was installed. The practical reason is cost: API-based assistants rate-limit heavy usage, so validating the protocol in tests first avoids burning quota while debugging.

Publishing on Smithery

Smithery is a registry of MCP servers that makes an integration installable by anyone. The demo server was published there, so other developers can browse its tools, run them from the web interface, and copy a configuration snippet straight into their client.

One caveat from the tutorial: the one-line install command Smithery suggested did not work on the author's machine, so the repository README documents a manual configuration instead. Running the server through npx was also inconsistent, and using the full npm exec form worked where the shorthand failed.

The registry's practical value is discovery. Instead of every developer writing a Slack or database connector from scratch, you search the registry, read the tool list, and install what fits.

Connecting the Server to Cursor and Claude Desktop

MCP servers need a compatible client. Two popular options are Cursor, an AI-first code editor built on VS Code, and Claude Desktop, Anthropic desktop app. Not every chat product supports the protocol yet, since the client must implement tool calling against MCP servers.

The setup is a JSON configuration file. In Cursor, open the command palette, search for MCP settings, add a new server entry, and paste the configuration. The status indicator turns green when the connection succeeds, and the editor lists the tools the server exposes.

In Claude Desktop the flow is similar: open the developer settings, edit the configuration file, and restart the app. Two real-world snags appeared in the demo. First, console.info output broke Claude Desktop because the app tried to parse it as JSON, so the server logs through console.error, which the app ignores. Second, the app launched the server with a different Node.js binary, so the configuration had to point at the exact Node 23 path to get native TypeScript support.

Once connected, asking questions in agent mode works end to end: the assistant recognizes the intent, fills the tool parameters, asks for permission to run, and returns the API result. The demo answered questions like "how many talks were given in 2024?" and "are there videos about RAG?" directly from the published server.

Ready-Made Integrations You Can Plug In

The ecosystem around MCP grew fast after the November 2024 launch. The reference servers repository alone includes connectors for search, messaging and databases, and Smithery aggregates many community servers beyond that.

The tutorial highlights a first example that stood out: Resend, an email automation API, whose MCP server let the assistant compose and send an email from the editor with no integration code written at all. Other examples cover web search, databases and file storage.

A practical pattern is composition: chain servers so one tool's output feeds another. The demo suggests combining the content API with the Brave Search server, so the assistant can first look something up on the web and then enrich the answer with structured data.

IntegrationWhat it doesWhere to find it
Brave SearchWeb search from the chatReference servers repo
SlackPost and read messagesReference servers repo
PostgreSQLQuery a database read-onlyReference servers repo
Google DriveSearch and read filesReference servers repo
ResendSend transactional emailSmithery registry

Practical Lessons From the Build

The tutorial surfaces several lessons that apply to any MCP project, and they mostly concern cost and compatibility rather than the protocol itself.

  • Test tools in isolation before wiring them into a paid assistant, because rate limits can lock you out for hours during development.
  • Pin the Node.js version in the client configuration; native TypeScript support requires Node 23 or the flagged builds of 22.6.
  • Route server logs through console.error when the target client is Claude Desktop, which misparses other output levels.
  • Verify the registry's install command on your own machine, and keep a manual fallback in your README.
  • Expect parameter validation to save you: the client enforces the schema before your code runs, so a missing argument becomes a retry rather than a silent failure.

FAQ

What is the model context protocol in simple terms?

It is an open standard that lets AI assistants call external tools through standardized servers. A tool declares its name, description and parameters, and the assistant fills in the arguments and invokes it during a conversation.

Who created the model context protocol?

Anthropic, the company behind Claude, announced and open-sourced the protocol on 25 November 2024. The specification and SDKs live in public repositories under the modelcontextprotocol organization.

Do I need to write code to use an MCP server?

No, for servers someone else published. You copy a configuration snippet into a client such as Cursor or Claude Desktop and start asking questions. You only write code when publishing your own server.

Which clients support MCP?

Cursor, Claude Desktop and Windsurf support connecting MCP servers, and the tutorial points to a community list of alternative clients. Support in general-purpose chat products varies because each client must implement the protocol.

Can MCP run fully offline?

The protocol itself is local, but whether a session is offline depends on the server and the model. The tutorial mentions running local models through Ollama with an MCP host CLI to test without cloud calls, while typical setups call hosted model APIs.

Why does MCP reduce hallucinations?

Because the assistant answers from data returned by a live tool call instead of relying only on training data. Fetching the real pull request status or database count anchors the answer to the source.

What language do I use to build an MCP server?

The official TypeScript SDK targets Node.js, and the demo ran TypeScript files directly on Node.js 23 with no transpiler. SDKs for other languages exist, but TypeScript is the most documented path.

How do I test an MCP server without spending API credits?

Write automated tests that create an MCP client and call your tools directly, as the demo did with the Node.js test runner. Validate everything in tests first, then connect the assistant.

Is MCP a replacement for writing API integrations?

For AI-driven workflows, it replaces hand-written Claude Code: the server wraps the API once and any MCP client can use it. Your application code that calls the same API outside an assistant context still needs its own integration.

Turn Your Own Tutorials Into Articles

This walkthrough started as a thirty-minute video, and the core insight survives the format change: a protocol that makes tools speak to assistants also makes knowledge easier to reuse. If you publish tutorials, interviews or explanations on YouTube and want them searchable as written articles, Skala Blog converts a video URL into a structured draft: paste the link, get the transcription, review the article before publishing.

Source video