MCP Servers – What, How and the Future?

The What

What is MCP?

MCP stands for model context protocol. It was introduced by Anthropic, the company behind Claude AI. If we try understand MCP by its full form then it is simply a protocol that guides us to provide context to a particular LLM model efficiently. Anthropic mentions on their website that MCP is like USB-C port for the AI applications. If we think of the LLM model as a computer and the context of the discussion as the accessory then MCP is the USB-C port for these two tools. It acts as the connecting bridge for these two tools to meet and generate an appropirate result. Essentially, MCP acts as a middleware in this whole scene where it allows the LLM to connect to different resources and extend its capabilities.

We know that any LLM is either holding a lot of data available on the internet or searches the internet on the go to find the result of the query which we put in as a prompt. To extend this knowledge base in the form of a database or any kind of resource, the LLM model needs to have access to the new resource that we want to feed in to the LLM model. An example of this can be a live cricket match. The data of the live cricket match cannot be readily available to LLMs as part of their training data. To solve this problem, we need to provide an external data source to the LLM. MCP solves this problem of connecting the data source or providing the data source to the LLM. It provides the protocol to connect the LLM to the data source by making an intermediate middleware between both.

What is MCP Server?

MCP server server is the software tool that is implemented with the help of MCP protocol. It is just a regular server which enables the connection between the LLM model and the outside resource that the LLM model needs to connect with.

A LLM model can connect with multiple MCP servers which provide diverse capabilities or access to diverse resources.

Let us take an example where we want to get the live cricket match score. We can ask the LLM the question. If there is any MCP server attached with the LLM then we can use the smartness of the LLM to reach out to the MCP server for data. When we ask the LLM this question it is its language capability that understands that it does not have this information and it also understands that it can reach out to the MCP server for this extra information. In this case the LLM would reach out to the MCP server for help and would display the results in some human language form after getting the data from the MCP server.

The How

The connection part

Traditionally servers have been commincating with clients over HTTP protocol in many forms. REST is a very common practice through which clients connect with servers for data exchange over the HTTP protocol.

MCP servers communicate with the LLM model host on standard input output or stdio. This means the standard input output of the process (server in this case) in keyboard text form which can be underderstood as the input or output given to the shell of the OS or the terminal if we are running the process directly through the terminal.

To understand this part in detail, for an instance, we can assume the LLM model as a human giving input in text to the MCP server and the MCP server will result in the form of text back to LLM model. This communication can be carried out by connecting the two parts of the story i.e. the process which runs the LLM model and the process which runs the MCP server with the help of standard input and output.

Components Of MCP Server

  • MCP Hosts: These are programs which have the LLM encoropated in them like Claude Desktop, IDEs like Cursor, chatGPT desktop application, Perplexity desktop application, or other AI tools that want to access data through MCP.
  • MCP Clients: It is basically the function or client inside the AI software application that establishes and maintains the connection with the MCP server.
  • MCP Servers: This the actual server written where the actual business logic lies. These are essentially lightweight programs that each expose specific capabilities through the standardized Model Context Protocol
  • Local Data Sources: Your computer’s files, databases, and services that MCP servers can securely access
  • Remote Services: External systems available over the internet (e.g., through APIs) that MCP servers can connect to

Functionalities Offered By MCP Servers

  • Resources: We can directly expose complete resources like databases, file contents, API gateways etc.
  • Promots: Prompts enable servers to define reusable prompt templates and workflows that clients can easily surface to users and LLMs.
  • Tools: We can expose particular functionalities in the form of functions. The server can take input from the LLM and produce the output after performing some computations to the LLM.
  • Sampling: It is way to inform about LLM completions to the MCP server through the client.
  • Roots: Root are used to define the boundaries of the MCP server under which it can operate.
  • Transports: Transport is the functionality that enables the how the communication can be done between the client and the MCP server. It manages the underlying functionality on how the messages sent between the client and server.

How To Create A Basic MCP Server

Here, I will be creating a basic MCP server which mimics a functionality exposed by the server for a banking application. Since, we cannot feed all the banking related data directly to the LLMs, this kind of application can come really handy for performing banking related tasks.

Step: 1

Create a npm repository install the following packages –

  • @modelcontextprotocol/sdk
  • zod

Here, @modelcontextprotocol/sdk contains the core functionality of creating an MCP server and conencting it to the MCP client. The below image contains the code for creating an MCP server.

Step 2:

Create an entry file typcally named as index.js or app.js. In this tutorial, I have kept it as index.js.

Here, we first create the server object and name and version parameters and then start the server to listening mode by connecting the server to the transport. Transport allows the server to communicate with the client in stdio mode in this particular case. We can also design transports where we can connect to MCP server which are hosted on a remote location.

Step 2:

Create tool for performing the computation inside the server.

These tools are recognized the LLM too. They are called when a specific task has to be performed. For instance, If I want to get the data of a customer by his name, the tool with the first arguement as “getCustomerByName” is recognized by the LLM and it is called to get the computed result. These tool names should named in a way that they recognized by the LLM in natural language.

Step 3:

Connect the server code to the MCP client by giving configurations. Here, I am using cursor IDE which has the MCP client built in.

Inside the Cursor IDE, if we go inside the setting, there is dedicated tab for MCP.

We need to click on the “Add new global MCP server” button to add the configurations.

The file with the name – mcp.json contains these configurations. Since, it is going to be essentially a node server, the command key has the value as node and the args key has the value as the file path to the index file. It is same as running the server by typing the command “node index.js” in the terminal. Once, it runs through the client without any errors we can start using the server with the LLM.

The code is available here in the repository – https://github.com/BooleanBuffer/mcp-bank-tools

The Future

MCP can be of a great use since it extends the functionality of the LLM by connecting external resources to the LLM.

A few good examples of this can be –

  • If Github exposes tools in their MCP server which would facilitate commit to the repositories then we can directly ask the LLM to commit the files in the repository.
  • If Slack exposes tools in their MCP server then we can find messages which have some context related to a particular thread in the slack organization.

All these servers can be connected to our personal LLM of choice in our phone or laptop computers and we can perform very specific and operations by just asking the LLM in natural language.