{"id":9590,"date":"2025-07-10T13:22:04","date_gmt":"2025-07-10T11:22:04","guid":{"rendered":"https:\/\/www.kubicek.ai\/?post_type=lexicon&#038;p=9590"},"modified":"2026-07-27T13:41:01","modified_gmt":"2026-07-27T11:41:01","slug":"mcp-model-context-protocol","status":"publish","type":"lexicon","link":"https:\/\/www.kubicek.ai\/en\/lexicon\/mcp-model-context-protocol\/","title":{"rendered":"MCP (Model Context Protocol)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Think of the Model Context Protocol as a universal adapter or translator for artificial intelligence. Today developers have to wire every AI model up to every application separately, which is inefficient. MCP creates a common language that all the systems involved understand. Thanks to it, any AI model can easily &#8220;talk&#8221; to various tools \u2013 to pull data from a company database, say, or send a message into a chat \u2013 without needing a bespoke solution every time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Model Context Protocol (MCP) is an open standard designed to unify communication between generative AI models and external sources such as databases, APIs or other software tools. The protocol works on a client-server principle, where the AI model (the client) can discover and call functions provided by an external server in a standardised way. The goal of MCP is to eliminate the need to build specific integrations for every combination of model and tool, thereby supporting interoperability and enabling the development of more complex and more capable AI agents.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">The Model Context Protocol (MCP) is an open standard that unifies the way artificial intelligence communicates with external tools and data. Think of it as a <strong>USB-C port for AI<\/strong>: instead of having to create a unique connection for every AI model and every application (a calendar, a database, an internal company system), MCP provides a universal interface. This lets any compatible AI model &#8220;speak&#8221; easily and securely to any tool that also supports MCP.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The aim is to simplify developers&#8217; work and make it possible to build more complex and more capable AI assistants and agents that can work with current data and carry out tasks inside your applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How MCP works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The protocol works on a <strong>client-server<\/strong> architecture:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>MCP server<\/strong>: a small program acting as a &#8220;translator&#8221; for a particular application or data source (GitHub, Slack, a database). It exposes that tool&#8217;s functions (&#8220;read the latest messages&#8221;, &#8220;create a new task&#8221;) and data (&#8220;list the files in the project&#8221;) in the standardised MCP format.<\/li>\n\n\n\n<li><strong>MCP client<\/strong>: part of the AI application (a desktop chatbot such as Claude, or a development environment). The client communicates with the server, finds out what tools and data it offers, and sends it requests on behalf of the AI model.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">When a user asks the AI for something that requires external data (&#8220;What meetings do I have today?&#8221;), the AI application (the client) sends a standardised query to the calendar MCP server. The server performs the action, returns the data in a standardised format, and the AI model then uses it to generate an answer.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Code example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following simplified Python example shows how to build a simple MCP server that exposes one tool to an AI model: <code>get_weather<\/code>. The tool returns the current weather for a given city. The code uses the <code>FastMCP<\/code> library, which makes the whole process easier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First the required libraries have to be installed:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-2c4616da80c6a08c65af8e6b7b37b718\"><code>pip install \"mcp&#91;cli]\" httpx\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The server code (<code>weather_server.py<\/code>) in Python<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-7e51967f5f94e1068a284b7461770b3a\"><code>import httpx\nfrom mcp.server.fastmcp import FastMCP\n\n# 1. Initialise the MCP server with a unique name\n# This name identifies the server inside AI applications.\nmcp = FastMCP(\"weather_forecast_server\")\n\n# 2. Define a tool using the @mcp.tool() decorator\n# The decorator makes the function available as a tool over MCP.\n# The docstring is very important - the AI model learns from it\n# what the tool does and which parameters it accepts.\n@mcp.tool()\nasync def get_weather(city: str) -&gt; str:\n    \"\"\"\n    Fetches the current weather for a specified city.\n    \n    :param city: The name of the city (e.g., 'Prague', 'London').\n    :return: A string describing the current weather conditions.\n    \"\"\"\n    try:\n        # Using an external API (here wttr.in) to obtain the data\n        async with httpx.AsyncClient() as client:\n            # ?format=3 is a special format for brief text output\n            response = await client.get(f\"https:\/\/wttr.in\/{city}?format=3\")\n            response.raise_for_status()  # Checks that the request succeeded\n            return response.text\n    except httpx.HTTPStatusError as e:\n        return f\"Error retrieving weather data for {city}: {e.response.status_code}\"\n    except Exception as e:\n        return f\"An unexpected error occurred: {str(e)}\"\n\n# This code runs only if the file is executed directly.\n# It allows the server to be started for development and testing.\nif __name__ == \"__main__\":\n    mcp.run_dev()\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>How to run it and what happens:<\/strong><\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Save the code as <code>weather_server.py<\/code>.<\/li>\n\n\n\n<li>Start the server from a terminal with: <code>python weather_server.py<\/code>.<\/li>\n\n\n\n<li>The server is now running and &#8220;listening&#8221; on a local port. Any AI application with an MCP client (for example Claude Desktop) can connect to it.<\/li>\n\n\n\n<li>When the user of the connected AI application asks &#8220;What is the weather in Prague?&#8221;, the model sees that it has the <code>get_weather<\/code> tool available.<\/li>\n\n\n\n<li>The model &#8220;calls&#8221; this tool with the parameter <code>city='Prague'<\/code>.<\/li>\n\n\n\n<li>Our server runs the function, sends a request to <code>https:\/\/wttr.in\/Prague?format=3<\/code>, receives the reply (for example &#8220;Prague: \u2600\ufe0f +22\u00b0C&#8221;) and passes it back to the AI model.<\/li>\n\n\n\n<li>The AI model uses this information to formulate the final answer for the user.<\/li>\n<\/ol>\n","protected":false},"featured_media":0,"template":"","class_list":["post-9590","lexicon","type-lexicon","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.kubicek.ai\/en\/wp-json\/wp\/v2\/lexicon\/9590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kubicek.ai\/en\/wp-json\/wp\/v2\/lexicon"}],"about":[{"href":"https:\/\/www.kubicek.ai\/en\/wp-json\/wp\/v2\/types\/lexicon"}],"wp:attachment":[{"href":"https:\/\/www.kubicek.ai\/en\/wp-json\/wp\/v2\/media?parent=9590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}