custom-mcp-server

custom-mcp-server

Exposes custom Python functions as tools and integrates with Ollama for tool calling.

Category
Visit Server

README

Ollama MCP Demo

This demo shows how to create a custom MCP server to expose custom Python functions as tools. It also demonstrates how a custom MCP client class can be used to integrate the MCP server with Ollama. Both, the MCP server and Ollama are independent and can be run on different machines.

Add Tools to your MCP Server

To add new tools to the MCP server, simply create Python functions in mcp_server/tools. Once created, add them to the TOOLS tuple in mcp_server/__main__.py which is used to register them to the MCP server.

# mcp_server/__main__.py
from mcp_server.tools import echo
...
SERVER = FastMCP(name="custom-mcp-server", **SERVER_CONFIG)
TOOLS = (echo,)  # add functions here
...

Running the MCP Server

  1. (Optional) Configure the environments in the docker-compose.yml file (ports, ollama configs, ...).

  2. Start the services. This spins up an Ollama instance and the MCP server.

    docker compose up -d
    
  3. (Optional) To download ollama models once the containers are running, use

    docker compose exec ollama ollama pull <your model>
    

The Ollama server can then be accessed at http://localhost:11434 and the MCP server at http://localhost:7777/mcp (replace ports with your configuration).

MCP Client Usage

Install the dependencies used for the MCP client

uv sync

You can then use the mcp_client.client.MCPClient class to communicate with the MCP server like this:

from mcp_client.client import MCPClient

mcp_client = MCPClient(host="localhost", port=7777)

# list available tools
tools = await mcp_client.list_tools()
...

# call a tool
result = await mcp_client.call_tool(tool_name="some_tool", arguments={"some_arg": "value"})
...

Integrating it with Ollama can be done like so:

from mcp_client.client import MCPClient
from ollama import Client as OllamaClient

mcp_client = MCPClient(host="localhost", port=7777)
ollama_client = OllamaClient("http://localhost:11434")

# invoke llm
response = ollama_client.chat(
    model="qwen3:4b",
    messages=[{"role": "user", "content": "Echo this message 'Hi, Alice!'"}],
    tools=await mcp_client.list_tools(),
)

print(response.message.content)

# handle tool calls
if tool_calls := response.message.tool_calls:
    for tool_call in tool_calls:
        tool_name = tool_call.function.name
        arguments = tool_call.function.arguments
        print("Calling", tool_name, "with arguments", arguments)
        tool_result = await mcp_client.call_tool(tool_name, arguments)
        print("Result: ", tool_result)

Helpful Links

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured