How to Build an MCP Server: A Practical Guide for Marketing Teams
How to build an MCP server that gives an AI assistant read-only access to marketing data: architecture, SDKs, authentication, security, testing and when not to build.
02 / In this article
To build an MCP server, you write a small program that exposes your data as tools, resources or prompts through the Model Context Protocol, using an official SDK, and you run it locally or behind an authenticated HTTP endpoint. For a marketing team the sensible first version is read-only: it lets an AI assistant look up numbers from a report, a warehouse or a tracking sheet, and it cannot change anything. This guide explains the architecture, the choices a developer will face, the security rules from the official documentation, and the cases where you should not build a server at all.
Key Takeaways
- A server is a thin layer, not a platform. It wraps a source you already have and describes a few operations that an AI application can call.
- Check for an existing server first. If the data lives in a common product, a maintained server may already exist, and a custom one adds code you must secure and update.
- Start read-only. The MCP specification says servers must validate inputs, apply access controls, rate limit calls and sanitize outputs. A read-only credential limits the damage when something goes wrong.
- Match authentication to the transport. The authorization specification says HTTP servers should follow its OAuth-based flow, while stdio servers should take credentials from the environment instead.
- Test with the Inspector before any assistant touches it. Then keep a human in the loop for anything that is not a plain lookup.
What does building an MCP server involve?
Building an MCP server means writing a program that speaks the Model Context Protocol and offers an AI application a defined set of operations on your data. If you need the basics first, our explainer on what MCP is covers them.
The work splits into five parts: decide what the assistant may ask, describe those operations as tools or resources, connect each to the source, secure it, then test and maintain it. The code is short because the SDK handles the protocol. Most of the effort goes into choosing what to expose and protecting it. The marketer knows which questions matter, the developer knows what is safe to expose.
How do the host, the client and the server fit together?
An MCP host is the AI application, it creates one MCP client per server, and each client keeps a dedicated connection to its server. The MCP architecture overview names three participants: the host (for example Claude Code or Claude Desktop), the client inside it, and the server that provides context.
A single request travels the same path each time. The person asks a question, the host decides whether a tool would help, the client sends a tools/call message to the server, and the server returns a result that the model uses in its answer. The messages use JSON-RPC 2.0, which means a developer can read them directly when debugging.
The protocol has a data layer (the messages) and a transport layer (how they travel), and you choose the transport separately. As of October 2026 the latest specification revision on the official site is 2026-07-28, which describes MCP as stateless: each request carries its own protocol version and capabilities, where earlier revisions used a handshake and sessions. The SDKs hide this, but it is a reason to build on a current SDK instead of an old tutorial.
Should you build a server at all?
Build a custom server only when your data is private or your rules are specific and no maintained server covers the need. Every server you write is software your team has to secure, update and explain.
The MCP project helps you check. Its servers repository holds reference implementations that it describes as educational examples. The official MCP Registry is, as of October 2026, in preview: a metadata catalogue of publicly accessible servers that points to packages hosted elsewhere and delegates code scanning to others. A listing is a starting point for your own review, not a guarantee.
Use the figure as a first filter:
- Common product, few rules. Usually covered by an existing server. See our roundup of MCP tools for marketers and our Search Console MCP guide.
- Common product, many rules. Keep the existing server and put your rules in a saved prompt, not in new code.
- Private source, few rules. The case this guide targets: an export, a warehouse view, a tracking sheet or an internal database.
- Private source, many rules. A custom server is justified, but plan it as a project with an owner and a maintenance budget.
If one person reads a report once a week, a scheduled export is simpler and easier to audit.
Not sure whether to build or reuse?
Tell us which data you want an assistant to read. We help you decide between an existing server, a small custom one or a simpler automation.
Explore AI workflowsWhat should the server expose: tools, resources or prompts?
An MCP server can expose tools, resources and prompts. The architecture page defines them as executable functions, data sources that provide context, and reusable templates that structure an interaction.
For marketing data, tools carry most of the value. The tools specification calls them model-controlled: each has a unique name, a description and a JSON Schema for its inputs, and the model decides when to call it. A good first set is small and specific: get_campaign_spend with a date range, list_top_pages with a limit, get_conversion_summary for one channel. Narrow tools are easier to validate and audit than one run_any_query tool.
Four rules for the tool list. Give each tool one job. Name it the way your team does, because the model reads the name and description to choose. Bound every input with types, ranges and allowed values. Return compact answers with the time zone, currency and freshness of the data stated.
The specification separates two kinds of failure. An unknown tool or malformed request is a protocol error. A failed lookup or an invalid date is a tool execution error, returned with isError: true so the model can read it and correct itself. "Date range must be 31 days or fewer" helps it recover, "Error 500" does not.
Which SDK and language should you pick?
Use the official SDK in the language your developer already works in. The MCP site lists official SDKs for TypeScript, Python, C#, Go, Rust, Ruby, Java, Swift, PHP and Kotlin, and classifies them in tiers by feature completeness, protocol support and maintenance commitment. As of October 2026, TypeScript, Python, C#, Go, Rust and Ruby are Tier 1, Java is Tier 2, and Swift, PHP and Kotlin are Tier 3.
If you have a choice, pick a Tier 1 SDK in the language of the person who will still own the code in a year, and run it where your team already hosts services.
What does a minimal server look like?
A minimal server is a few lines: create the server object, declare tools with typed arguments, and start it on a transport. The official build-a-server tutorial does this in Python, and the examples below are copied from it.
Installation, from the tutorial (the Python tutorial states it needs Python 3.10 or higher and Python MCP SDK 2.0.0 or higher):
uv add "mcp[cli]"
Creating the server, from the same tutorial:
from typing import Any
import httpx2
from mcp.server import MCPServer
# Initialize MCPServer
mcp = MCPServer("weather")
Declaring a tool is done with a decorator, and the SDK builds the tool definition from the type hints and the docstring. The tutorial's get_alerts tool begins like this:
@mcp.tool()
async def get_alerts(state: str) -> str:
"""Get weather alerts for a US state.
Args:
state: Two-letter US state code (e.g. CA, NY)
"""
Starting it on the stdio transport, again from the tutorial:
if __name__ == "__main__":
mcp.run(transport="stdio")
Source for all four snippets: the "Build an MCP server" tutorial at modelcontextprotocol.io, with the full weather server at github.com/modelcontextprotocol/quickstart-resources. The tutorial uses a public weather API. Your version would read from your own source. Your developer should follow the current tutorial for their language, because SDK versions move.
One rule from the tutorial prevents a common bug. For a stdio server, never write to standard output. The tutorial says writing to stdout corrupts the JSON-RPC messages and breaks the server, and that print() writes there by default. Use a logger that writes to stderr instead. HTTP-based servers do not have this limit.
Local or remote: which transport should you use?
Use stdio when one person runs the server on their own machine, and Streamable HTTP when a team needs to share it. The architecture page says local servers on the stdio transport typically serve a single client, while remote servers on Streamable HTTP typically serve many.
| stdio (local) | Streamable HTTP (remote) | |
|---|---|---|
| How it runs | The client launches it as a subprocess | A service at a URL |
| Who uses it | One person, one machine | A team, many clients |
| Credentials | From the environment | Per user, through authorization |
| Main risk | Code running on a laptop with that user's rights | An internet-facing endpoint |
The security page notes that local servers run with the privileges of the client, so run only servers you trust and read the exact command before approving it. For a remote server, the Streamable HTTP specification says servers must validate the Origin header to prevent DNS rebinding attacks, should bind to localhost (127.0.0.1) when running locally, and should implement proper authentication for all connections. The older HTTP plus SSE transport is deprecated.
How should authentication and authorization work?
Authentication depends on the transport: HTTP servers should follow the MCP authorization specification, which is built on OAuth 2.1, and stdio servers should read credentials from the environment. The specification states that authorization is optional, that HTTP-based implementations should conform to it, and that stdio implementations should not follow it and should retrieve credentials from the environment.
For a remote server, the MCP server acts as an OAuth resource server, the client as an OAuth client, and a separate authorization server issues tokens. The points that decide whether it is safe:
- Audience binding. Servers must validate that a token was issued specifically for them and must not accept or pass on any other token.
- No token passthrough. The security page calls it an anti-pattern to forward a client's token to a downstream API without validation: it can bypass rate limits and monitoring and blurs the audit trail.
- Least-privilege scopes. Start with low-risk read scopes and request more only when needed. Broad wildcard scopes are listed as a common mistake.
- Tokens in headers only, never in the URL, with 401 for missing or invalid tokens and 403 for insufficient permissions.
Separately, the credential your server uses to reach the data source matters most for a read-only design. Create a dedicated account or API key with read access to only the datasets the tools need, keep it in a secret manager or environment variable (never in the repository) and note who rotates it. If the source cannot issue read-only credentials, put a read-only view or a copy of the data in front of it.
How do you keep a marketing data server safe?
Keep it safe by stacking controls, so that no single failure gives write access or exposes unrelated data. The MCP tools specification says servers must validate all tool inputs, implement proper access controls, rate limit tool invocations and sanitize tool outputs. It also says there should always be a human in the loop with the ability to deny tool invocations.
Build the layers from the bottom:
- Read-only credential. A hostile instruction cannot write through a credential that cannot write. Get this one right first.
- Rate limits and logs. Record the tool, arguments, caller and time. Never log secrets or full personal data.
- Validated inputs. Reject anything outside the schema. Never paste model-supplied text into SQL: use parameters, an allowlist of tables and a row limit.
- Human review. For a lookup, a person reading the answer is enough. A change to an ad budget, a tracking tag or a customer record is approved by a person in the tool where it happens.
Two more points. The specification says clients must treat tool annotations as untrusted unless they come from a trusted server, so enforce read-only in the credential, not in a label. And tool results flow back into the model's context: if your data contains text written by outsiders, such as form entries or reviews, a hostile string can try to steer the assistant. Return fields instead of free text where you can. Expose aggregates by default, and treat any tool that returns individual customer records as a separate decision with its own approval.
Want reporting data an assistant can read safely?
We can scope a read-only setup on your own tracking and reporting data, with people supervising each step.
See analytics and trackingHow do you test a server before anyone uses it?
Test with the official MCP Inspector first, then with a real client, and finish with a short list of bad requests. The Inspector is the project's developer tool for inspecting MCP servers. According to its repository, you start it with npx @modelcontextprotocol/inspector for the web interface, or add --cli for a scriptable command-line mode that suits automation and continuous integration.
A simple plan that a marketer and a developer can run together:
- List the tools and check the names and descriptions read clearly to someone who has not seen the code.
- Call each tool and compare the result with the same figure in your reporting tool.
- Send bad inputs: a wrong date format, a huge range, an unknown identifier. The error should be useful and nothing should crash.
- Try to write by every route you can think of and confirm the credential refuses it.
- Connect a real client and ask five real questions. If the model picks the wrong tool, fix the description.
- Check the logs for each call and no secrets.
The Inspector README says it manages OAuth tokens, client secrets and stdio environment values, stores them in the operating system keychain by default and, where none exists, in a file that is unencrypted unless you supply a key. Use test credentials while you experiment. A secure server can still be wrong, for example by mixing time zones, so keep a short list of known-correct numbers and re-run it after every change.
How do you deploy and maintain a server?
Deploy it like any small internal service: a known owner, a repeatable build, secrets outside the code and monitoring that a person reads. The protocol adds two things. The specification has dated revisions and the SDKs follow them, so review each SDK update against the changelog on the MCP site. And tool lists can change, but change notifications are best effort, so keep tool names stable.
Keep a one-page runbook: the data source, the credential and its owner, one sentence per tool, how to switch the server off quickly, and who to contact. Review access when someone leaves and call counts monthly: a tool nobody calls is a tool to remove. A server over a tracking sheet is also more useful when a clean pipeline feeds the sheet, which is the kind of work covered by our business process automation service.
What should a marketing team decide before a developer starts?
Write a one-page brief that answers six questions: ten real questions in your team's words, the system of record for each answer, which fields are personal or commercially sensitive, who may use the server, a plain statement that the first version cannot change anything, and the named owner who answers when a number looks off.
If the source is a website, a form or a tracking setup, the data is only as good as the build. Clean event names, consistent campaign parameters and structured forms make every later server easier, which is a reason to look at your web design and build alongside the server. Versai's AI workflows service designs custom automated systems on a client's own tools, with people supervising, and the AI workflows page describes the scope. To see servers from the user side, read our guides to Claude and MCP and ChatGPT and MCP.
Frequently Asked Questions
What is an MCP server in simple terms?
A program that offers an AI application a list of things it can look up or do, described in a standard format. The application reads the list, calls an operation when needed and uses the result in its answer.
Do I need to be a developer to build one?
You need a developer to build and run it. A marketer does the most valuable early work: listing the questions, naming the data source and deciding what is sensitive. The code is short with an official SDK, but securing and maintaining it is engineering work.
Should a marketing data server be read-only?
Yes, for the first version. A read-only server cannot change budgets, tags or customer data, even if the assistant misreads a request. The specification also expects input validation, access controls, rate limiting and a human in the loop.
Is it safe to run an MCP server on my laptop?
It can be, if you trust the code and limit what it reaches. The security guidance warns that local servers run with the client's privileges, so read the command before you approve it and give the server minimal credentials.
When should I use an existing MCP server instead?
When your data lives in a common product and a maintained server already covers your questions. Review its code, permissions and maintainers first. Build your own only for private data or specific rules.
How do I test an MCP server?
Use the official MCP Inspector to list and call each tool, then send bad inputs and try to write. Finally connect a real client and ask real questions.
How long does a server need maintenance?
For as long as it runs. SDKs and specification revisions change, credentials need rotating and tools need pruning, so name an owner.
Next steps
Write the one-page brief, then check whether an existing server already answers your questions. If it does, start with the roundup of MCP tools for marketers and our Search Console MCP guide. If not, hand the brief to a developer and ask for a read-only prototype on stdio, tested with the Inspector. If you want help scoping a setup on your own tools, see our AI workflows service, the analytics and tracking service and business process automation, or get in touch with the data you want an assistant to read.
Sources
- Model Context Protocol, "Architecture overview": https://modelcontextprotocol.io/docs/learn/architecture
- Model Context Protocol, "Build an MCP server" (tutorial; code excerpts above): https://modelcontextprotocol.io/docs/develop/build-server
- Model Context Protocol, quickstart resources, weather server (Python): https://github.com/modelcontextprotocol/quickstart-resources/tree/main/weather-server-python
- Model Context Protocol, "SDKs": https://modelcontextprotocol.io/docs/sdk
- Model Context Protocol specification, "Tools": https://modelcontextprotocol.io/specification/latest/server/tools
- Model Context Protocol specification, "Authorization": https://modelcontextprotocol.io/specification/latest/basic/authorization
- Model Context Protocol specification, "Transports": https://modelcontextprotocol.io/specification/latest/basic/transports
- Model Context Protocol specification, "Streamable HTTP": https://modelcontextprotocol.io/specification/latest/basic/transports/streamable-http
- Model Context Protocol, "Security Best Practices": https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices
- Model Context Protocol, "The MCP Registry": https://modelcontextprotocol.io/registry/about
- MCP Inspector repository: https://github.com/modelcontextprotocol/inspector
- MCP reference servers repository: https://github.com/modelcontextprotocol/servers
Newsletter
One short email when we publish
Notes on AI, image, video and brand work, from the people who do it. No spam.