mcp-forge

mcp-forge

A FastAPI-style framework for building MCP servers in Python, enabling declarative tool definitions with automatic schema validation and multiple transport options.

Category
访问服务器

README

<div align="center">

<br />

<img src="https://raw.githubusercontent.com/nsfwbunny/mcp-forge/main/.github/assets/logo.svg" alt="mcp-forge" width="72" />

mcp-forge

The FastAPI-style framework for building MCP servers in Python.

Declarative tools. Auto-schema. Type-safe. Production-ready.

<br />

PyPI version Python CI Coverage License: MIT mypy

<br />

Quick Start  •  Documentation  •  Examples  •  Roadmap  •  Contributing

<br />

<!-- demo gif: replace the src below with your actual recording --> <img src="https://raw.githubusercontent.com/nsfwbunny/mcp-forge/main/.github/assets/demo.gif" alt="mcp-forge demo" width="720" />

<br />

</div>


Why mcp-forge?

Every MCP server you write starts the same way: hand-craft JSON Schema, wire a transport loop, handle notifications/initialized, redirect stderr, copy-paste validation logic. It's the same boilerplate every time.

mcp-forge eliminates all of it. You write a typed Python function. The framework derives the schema from your type hints, validates inputs at runtime, and exposes the tool over any transport — STDIO, HTTP, or SSE — without changing a single line of your logic.

Think of it as the FastAPI moment for MCP servers.

from mcp_forge import Forge

app = Forge(name="my-server", version="1.0.0")

@app.tool(description="Search the knowledge base")
async def search(query: str, limit: int = 10) -> list[dict]:
    """Returns ranked results for the given query."""
    ...  # your logic here

if __name__ == "__main__":
    app.run()  # STDIO — Claude Desktop / Cursor / VS Code ready

No JSON Schema by hand. No transport boilerplate. No config files.


⚡ Quick Start

pip install mcp-forge
mcp-forge new my-server && cd my-server
mcp-forge run --reload

Connect to Claude Desktop in 30 seconds:

{
  "mcpServers": {
    "my-server": {
      "command": "python",
      "args": ["-m", "my_server"]
    }
  }
}

Switch to HTTP transport with one flag:

mcp-forge run --transport http --port 8080

✨ Features

<table> <tr> <td width="50%">

🏗️ Declarative Tools Define tools as typed Python functions with @app.tool(). No schema files, no registration calls.

🧠 Auto JSON Schema Pydantic v2 under the hood. Full draft-07 JSON Schema generated from your type hints — automatically.

✅ Runtime Validation Inputs validated before execution. Errors surface as proper MCP-spec error responses.

🚀 Multi-Transport STDIO · HTTP · SSE. Switch transports at runtime — your tool code never changes.

</td> <td width="50%">

⏳ Async-First async def and def tools work side by side. No event loop management needed.

🔌 Contrib Routers memory · filesystem · web — production-ready tools, one-line include.

🧪 Testing Client ForgeTestClient calls tools directly — no running server, no mocking, no sockets.

📦 PEP 561 Typed Ships py.typed. Full mypy --strict and Pyright support out of the box.

</td> </tr> </table>


📚 Examples

Minimal server — 3 lines of logic

from mcp_forge import Forge

app = Forge(name="calculator")

@app.tool()
def add(a: float, b: float) -> float:
    """Add two numbers."""
    return a + b

@app.tool()
def multiply(a: float, b: float) -> float:
    """Multiply two numbers."""
    return a * b

app.run()

With contrib tools

from mcp_forge import Forge
from mcp_forge.contrib import memory, filesystem, web

app = Forge(name="agent-tools")
app.include(memory)      # remember(), recall(), forget(), list_memory()
app.include(filesystem)  # read_file(), write_file(), list_dir(), delete_file()
app.include(web)         # fetch_url()

app.run()

HTTP transport with custom config

from mcp_forge import Forge, ForgeConfig

app = Forge(
    name="api-server",
    config=ForgeConfig(
        transport="http",
        port=8080,
        cors_origins=["*"],
        max_tool_timeout=30,
    ),
)

@app.tool()
async def summarize(text: str, max_words: int = 100) -> str:
    """Summarize text to a given word count."""
    ...

app.run()

Unit testing — no server needed

from mcp_forge.testing import ForgeTestClient

client = ForgeTestClient(app)

def test_add():
    result = client.call("add", {"a": 2, "b": 3})
    assert result == 5

async def test_summarize_async():
    result = await client.acall("summarize", {"text": "Hello world"})
    assert isinstance(result, str)

📐 Architecture

mcp-forge
├── core/
│   ├── forge.py        ← Forge class — declarative app entrypoint
│   ├── schema.py       ← Auto JSON Schema from Pydantic v2 type hints
│   ├── validator.py    ← Input/output validation engine
│   ├── config.py       ← ForgeConfig dataclass
│   └── exceptions.py   ← MCP-aligned exception hierarchy
├── transports/
│   ├── stdio.py        ← STDIO — MCP spec 2024-11-05 compliant
│   ├── http.py         ← HTTP — FastAPI-based REST transport
│   └── sse.py          ← SSE — Server-Sent Events streaming
├── cli/
│   └── main.py         ← Typer CLI — new, run, list, build
└── contrib/
    ├── memory.py       ← Scoped in-process memory store
    ├── filesystem.py   ← Safe filesystem tools with path sandboxing
    └── web.py          ← HTTP fetch with timeout and error handling

Design principles:

  • Transport is a runtime concern — your tool code never changes between STDIO, HTTP, and SSE
  • Schema is derived, never written — if your types are correct, your schema is correct
  • Contrib is opt-inapp.include(memory) adds tools; you stay in control
  • Strict by default — mypy strict, ruff format + lint, 100% typed public API

🌍 Ecosystem Compatibility

Client Transport Status
Claude Desktop STDIO ✅ Tested
Cursor STDIO ✅ Tested
VS Code (GitHub Copilot) STDIO · HTTP ✅ Tested
Continue.dev HTTP · SSE ✅ Tested
Custom LLM agents HTTP · SSE ✅ Tested

📦 Installation

# Core only (STDIO transport)
pip install mcp-forge

# With HTTP + SSE transports
pip install "mcp-forge[http]"

# Everything
pip install "mcp-forge[all]"

Requires: Python 3.11+  ·  pydantic>=2.0


🤝 Contributing

Contributions are welcome. See CONTRIBUTING.md for the full guide.

git clone https://github.com/nsfwbunny/mcp-forge
cd mcp-forge
pip install -e ".[dev]"
pytest

<div align="center">

<br />

Built by Benni Alencar  ·  Part of the Benni OS open-source ecosystem

<br />

<sub>If mcp-forge saves you time, consider giving it a ⭐</sub>

</div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选