Skip to main content
Glama

Simple HTTP MCP Server

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

  1. Install dependencies:
    uv sync
  2. Run the server:
    uv run run-http
    or for stdio transport:
    uv run run-stdio
  3. Test the server:Note: you should be located on the root folder of the project so gemini config is used.
    gemini /mcp # This should show the tools available

Example:

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 or FastAPI 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:

  1. Define a context class:
    from dataclasses import dataclass, field @dataclass class Context: called_tools: list[str] = field(default_factory=list) def get_called_tools(self) -> list[str]: return self.called_tools def add_called_tool(self, tool_name: str) -> None: self.called_tools.append(tool_name)
  2. Instantiate the context and the server:
    from app.tools import TOOLS, Context from server.server import MCPServer context = Context(called_tools=[]) mcp_server = MCPServer(tools=TOOLS, name="test", version="1.0.0", context=context)
  3. Access the context in your tools:
    from server.models import Input from app.tools import Context async def my_tool(args: Input[MyToolArguments, Context]) -> MyToolOutput: # Access the context args.context.add_called_tool("my_tool") ...

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.

from server.models import Input async def my_tool(args: Input[MyToolArguments, None]) -> MyToolOutput: # Access the request auth_header = args.request.headers.get("Authorization") ...

Getting Started

Prerequisites

Installation

  1. Clone the repository:
    git clone <repository-url> cd simple-http-mcp
  2. Create a virtual environment and install dependencies:
    uv venv source .venv/bin/activate uv sync

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:

ruff check .

To automatically fix linting errors, run:

ruff check . --fix

Type Checking

To run the static type checker, use:

mypy .
-
security - not tested
F
license - not found
-
quality - not tested

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.

  1. How to test with Gemini Cli
    1. Features
      1. Stateful Context
        1. Accessing the Request
          1. Getting Started
            1. Prerequisites
            2. Installation
          2. Usage
            1. Development
              1. Linting
              2. Type Checking

            Related MCP Servers

            • -
              security
              F
              license
              -
              quality
              This 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
            • A
              security
              A
              license
              A
              quality
              A server that provides a persistent Python REPL environment through the MCP protocol, allowing execution of Python code, variable management, and package installation.
              Last updated -
              3
              24
              Python
              MIT License
            • -
              security
              F
              license
              -
              quality
              A 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 -
              1
              Python
            • -
              security
              F
              license
              -
              quality
              A 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

            View all related MCP servers

            MCP directory API

            We provide all the information about MCP servers via our MCP API.

            curl -X GET 'https://glama.ai/api/mcp/v1/servers/yeison-liscano/http_mcp'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server