jpolanco91/mcp-server-implementation
If you are the rightful owner of mcp-server-implementation and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This document provides a structured overview of a Model Context Protocol (MCP) server, which facilitates communication between Language Learning Models (LLMs) and external software tools.
MCP Server sample
This is an example of a Model Context Protocol (MCP) server that allows LLMs to access external software tools, just as functions, APIs, data resources, ....
Files
-
client_config/constants.pyThis file contains constants needed for configuration purposes in the server. This includes the server address. -
mcp_client.pyThis is the implementation of a MCP Client that allows an LLM to communicate and use the external resources. This file can be imported and integrated into any code where you are using an LLM or AI Agent that needs to interact with external tools. This client connects and communicates with the MCP server. -
mcp_server.pyThis is the implementation of the MCP server, this server uses an implementation of FastAPI called FastMCP that allows to create a server that handle the communication between LLMs and resources (tools, databases, APIs, ...). -
mcp_client_implementation.pyThis is the sample implementation of an scenario where an MCP client is used to communicate with the MCP server to be able to control any external resource. This can be used as a guide to integrate Agents and LLMs with the MCP server (through the MCP client) and connect to the external tools and services that the AI wants to manipulate. -
tools.pyThis is the file that have the tools that an AI (LLM or Agent) can use and manipulate. This can be functions, database calls/connections, APIs (web or in the code), etc... In this particular case, we have 2 functions as tools:hello_world(to make a greeting with a specific person's name) andadd(function that adds 2 numbers). -
tests/tools_test.pyThese are the unit tests for each tool, using the librarypytest.
Setup and installation
Installing Anaconda
First we must download and install Anaconda which is a distribution of libraries for Data Science, Machine Learning and AI which is based on the conda python library that allows to create environment and install dependencies. You must select the version for your operative system (Windows, Linux, macOS), download it and then follow the installation steps from the installer.
Setting up the environment and installing dependencies.
Clone the repository from github.
Then run this command to make Anaconda install the environment with all the required dependencies to run:
conda env create -f mcp-training-env.yml
This will create the mcp_training_env environment and will install all the included dependencies in it.
Running the server and client implementations
Change to the mcp_server directory with this command:
cd mcp_server
Before running the server and client implementations we must first activate the conda environment. Since we'll be running server and client we must open 2 terminals (or any other command line tool you have) in the same project/code root directory. Then in both we run this:
conda activate mcp_training_env
This activates the previously created mcp_training_env . Then in one terminal we start the server by running this:
python mcp_server.py
When the server starts if no other error is shown then we run the client implementation with this other command:
python mcp_client_implementation.py and you'll see an interactive screen with instructions allowing you to select and run any of the tools available.