Every AI assistant eventually needs to touch something outside the chat window: a database, a ticketing system, a file share. Before a common standard existed, each integration was custom glue code. The Model Context Protocol (MCP) is an open standard, introduced by Anthropic in November 2024, that defines one way for AI applications to talk to external tools and data sources. Build a server once and any MCP-compatible client can use it.
How MCP is structured
MCP uses a client-server model with three roles:
- Host: the AI application the user interacts with, such as a desktop assistant or an IDE.
- Client: a connector inside the host that keeps one connection to one server.
- Server: a small program that exposes capabilities to the client.
A server can expose three kinds of capabilities:
- Tools: functions the model can call, such as "create a ticket" or "run a query".
- Resources: read-only data the application can load as context, such as a file or a database record.
- Prompts: reusable prompt templates that users can pick.
Messages use JSON-RPC. Servers can run locally over standard input/output (stdio) or remotely over HTTP. The protocol continues to evolve, so always confirm details against the current specification at modelcontextprotocol.io.
Build a minimal server in Python
The official Python SDK includes a high-level helper called FastMCP. Install it with the CLI extras:
pip install "mcp[cli]"Create a file named server.py:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
@mcp.resource("greeting://{name}")
def greeting(name: str) -> str:
"""Return a personalised greeting."""
return f"Hello, {name}!"
if __name__ == "__main__":
mcp.run() # stdio transport by defaultThe function signature and docstring become the tool's schema and description. Clear names and docstrings matter, because the model reads them to decide when to call the tool.
Test it before connecting a client
The SDK ships an inspector you can use to call tools interactively:
mcp dev server.pyOpen the inspector, list the tools, call add with two numbers and confirm the result. Testing here separates server bugs from client configuration problems.
Connect it to a client
Most desktop clients register local servers in a JSON configuration file. The exact file location depends on the client, so check its documentation. The shape is usually:
{
"mcpServers": {
"demo": {
"command": "python",
"args": ["/absolute/path/to/server.py"]
}
}
}Restart the client, and the add tool should appear in its tool list.
Security checklist
An MCP server gives a model the ability to act, so treat it like any other API that accepts untrusted input:
- Least privilege. Give each server only the access it needs, and prefer read-only credentials.
- Validate inputs. Model-generated arguments can be wrong or manipulated. Validate and constrain them as you would any user input.
- Beware prompt injection. Content returned by a tool, such as a web page or a document, may contain instructions aimed at the model. Do not let tool output trigger sensitive actions without confirmation.
- Require confirmation for destructive actions such as deleting data or sending messages.
- Only run servers you trust. A local server runs with your permissions.
For broader application risks, see our guide to the OWASP Top 10:2025.
Where to go next
Once the basics work, add a tool that wraps one of your own APIs, then consider a remote HTTP deployment with authentication. If you build web back ends, the same thinking applies to how you design APIs in ASP.NET Core.