Skip to main content
Glama
basesmcp

basesmcp

by REKA3003

basesmcp

Turn any Python function into an auto-registered MCP tool with a single @mcp decorator, then expose them all over a FastMCP server.

Install

pip install basesmcp

Related MCP server: mcp-app

Quickstart

from basesmcp import mcp, serve

@mcp
def get_user(user_id: str) -> dict:
    """Fetch a user by id."""
    return {"user_id": user_id, "name": "Ada"}

@mcp(name="add_numbers", tags={"math"})
def add(a: float, b: float) -> float:
    """Add two numbers."""
    return a + b

if __name__ == "__main__":
    serve(name="My Product MCP", host="0.0.0.0", port=8000, path="/mcp")

Any function you decorate with @mcp becomes a tool; serve() registers them all and runs the server. The MCP client's model selects the right tool per request from its name, description, and type hints — so write clear docstrings and type hints.

Auto-discovery across modules

Keep tools in a package and let basesmcp import them for you:

from basesmcp import serve

serve(name="My MCP", discover="myproduct.mcp_tools", port=8000)

discover accepts a module name, a package name (all submodules are imported), or a list of names.

Auth (optional)

Plug your existing token validation in without basesmcp knowing the details:

from basesmcp import serve, bearer_auth
from fastmcp.server.auth import AccessToken

def verify(token: str):
    claims = my_validate(token)            # your existing logic
    if not claims:
        return None
    return AccessToken(token=token, client_id=claims["sub"], scopes=claims.get("roles", []))

auth = bearer_auth(
    verify=verify,
    authorization_servers=["https://auth.example.com"],
    base_url="https://mcp.example.com",
)
serve(name="My MCP", auth=auth, host="0.0.0.0", port=8000)

Read the caller identity inside a tool:

from basesmcp import mcp, current_token, current_claims

@mcp
def whoami() -> dict:
    return {"authenticated": current_token() is not None, "claims": current_claims()}

API

Symbol

Purpose

@mcp / @tool / @mcp_tool

Mark a function as a tool (bare or parameterized).

create_server(name=, instructions=, auth=, discover=, registry=)

Build a FastMCP server with all tools registered.

serve(..., host=, port=, path=, transport=)

Build and run the server.

bearer_auth(...), CallbackTokenVerifier

Optional auth wiring.

current_token(), current_claims(), current_access_token()

Current request context.

ToolRegistry

Isolated registry (e.g. for tests).

Best practice

Decorate framework-agnostic functions (plain functions or your service-layer methods) — not web-framework route handlers that depend on request globals. Give every tool a clear docstring and typed parameters so the client model can route to it accurately.

License

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      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.
      4
      130 PyPI
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Framework for building and running MCP servers as HTTP services. Define tools as pure Python functions, wire up with two lines, run with one command.
      -
    • A
      license
      B
      quality
      C
      maintenance
      Convert plain Python modules into MCP servers without decorators or boilerplate, automatically exposing functions as schematized tools.
      5
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Minimal MCP server allowing Python functions to be served as MCP tools over stdio or HTTP, with a built-in client for connecting to MCP servers.
      124 PyPI
      2
      Apache 2.0