Simple HTTP MCP Server
This project provides a lightweight server implementation for the Model Context Protocol (MCP) over HTTP. It allows you to expose Python functions as "tools" that can be discovered and executed remotely via a JSON-RPC interface. It is thought to be used with an Starlette or FastAPI application (see app/main.py).
How to test with Gemini Cli
- Install dependencies:
- Run the server:or for stdio transport:
- Test the server:Note: you should be located on the root folder of the project so gemini config is used.
Example:
Note: The example image is not updated with the latest changes.
Features
- MCP Protocol Compliant: Implements the MCP specification for tool discovery and execution.
- HTTP and STDIO Transport: Uses HTTP POST or STDIO for communication (Experimental only testing use).
- Async Support: Built on
Starlette
orFastAPI
for asynchronous request handling. - Type-Safe: Leverages
Pydantic
for robust data validation and serialization. - Stateful Context: Maintain state across tool calls using a context object.
- Request Access: Access the incoming request object from your tools.
- Dependency Management: Uses
uv
for fast and efficient package management. - Linting: Integrated with
Ruff
for code formatting and linting. - Type Checking: Uses
Mypy
for static type checking.
Stateful Context
You can use a context object to maintain state across tool calls. The context object is passed to each tool call and can be used to store and retrieve data.
To use a context object, you need to:
- Define a context class:
- Instantiate the context and the server:
- Access the context in your tools:
Accessing the Request
You can access the incoming request object from your tools. The request object is passed to each tool call and can be used to access headers, cookies, and other request data.
Getting Started
Prerequisites
Installation
- Clone the repository:
- Create a virtual environment and install dependencies:
Usage
For usage examples, please refer to the tests in the tests/
directory.
Development
This project uses several tools to ensure code quality.
Linting
To check for linting errors, run:
To automatically fix linting errors, run:
Type Checking
To run the static type checker, use:
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
A lightweight server implementation that exposes Python functions as discoverable tools via HTTP using the Machine-to-Machine Communication Protocol (MCP). Enables remote execution of Python functions through a JSON-RPC interface with async support and type safety.
Related MCP Servers
- -securityFlicense-qualityThis is an MCP server that facilitates building tools for interacting with various APIs and workflows, supporting Python-based development with potential for customizable prompts and user configurations.Last updated -Python
- AsecurityAlicenseAqualityA server that provides a persistent Python REPL environment through the MCP protocol, allowing execution of Python code, variable management, and package installation.Last updated -324PythonMIT License
- -securityFlicense-qualityA Python implementation of the MCP server that enables AI models to connect with external tools and data sources through a standardized protocol, supporting tool invocation and resource access via JSON-RPC.Last updated -1Python
- -securityFlicense-qualityA Python template for building Model Context Protocol (MCP) servers that expose tools via JSON-RPC, enabling secure and scalable context and tool invocation for language models.Last updated -Python