Skip to main content
Glama

FastAPI MCP-Style Server

by ilyoungkim

FastAPI MCP-Style Server

Minimal FastAPI implementation that mimics a subset of Model Context Protocol (MCP) functionality.

Features

  • Echo-style POST /mcp endpoint returning structured response (id, status, outputs)
  • JSON-RPC 2.0 endpoint /mcp/rpc supporting:
    • mcp.list_tools
    • mcp.call_tool (tools: echo, uppercase, query_manse, calc_daewoon)
  • GET usage helper /mcp
  • Pydantic models for request/response
  • Basic logging
  • Tests (pytest) for REST + RPC

Quick Start

python -m venv .venv source .venv/bin/activate pip install -r requirements.txt uvicorn main:app --reload

REST Usage

curl -X POST http://127.0.0.1:8000/mcp \ -H 'Content-Type: application/json' \ -d '{"inputs": {"text": "hello"}}'

JSON-RPC Examples

List tools:

curl -X POST http://127.0.0.1:8000/mcp/rpc \ -H 'Content-Type: application/json' \ -d '{"jsonrpc":"2.0","id":1,"method":"mcp.list_tools"}'

Call echo:

curl -X POST http://127.0.0.1:8000/mcp/rpc \ -H 'Content-Type: application/json' \ -d '{"jsonrpc":"2.0","id":"abc","method":"mcp.call_tool","params":{"name":"echo","arguments":{"text":"hello"}}}'

Call query_manse (first 5 rows):

curl -X POST http://127.0.0.1:8000/mcp/rpc \ -H 'Content-Type: application/json' \ -d '{"jsonrpc":"2.0","id":2,"method":"mcp.call_tool","params":{"name":"query_manse","arguments":{"limit":5}}}'

Call calc_daewoon (example date):

curl -X POST http://127.0.0.1:8000/mcp/rpc \ -H 'Content-Type: application/json' \ -d '{"jsonrpc":"2.0","id":3,"method":"mcp.call_tool","params":{"name":"calc_daewoon","arguments":{"yyyymmdd":"20250115"}}}'

Response example:

{ "jsonrpc": "2.0", "id": 3, "result": { "outputs": [ {"type": "json", "content": {"asc_diff_days": 3, "desc_diff_days": 2}} ] } }

Meaning:

  • asc_diff_days: 기준일 이후 다음 절기까지 (일수 / 3 반올림)
  • desc_diff_days: 기준일 이전 직전 절기까지 (일수 / 3 반올림)
  • 없으면 null

Environment Variables (DB)

VariableDefaultDescription
MCP_DB_HOST192.168.31.136MariaDB host
MCP_DB_PORT3306MariaDB port
MCP_DB_USERDB user
MCP_DB_PASSWORDDB password
MCP_DB_NAMEmanseDatabase name

Example run with overrides:

MCP_DB_HOST=127.0.0.1 MCP_DB_USER=app MCP_DB_PASSWORD=secret uvicorn main:app --reload

Run Tests

pytest -q

Next Ideas

  • Streaming (SSE) outputs
  • Prompts/resources primitives
  • Auth layer (OAuth / API key)
  • Tool change events
-
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 minimal FastAPI implementation that mimics Model Context Protocol functionality with JSON-RPC 2.0 support. Provides basic tools like echo and text transformation through both REST and RPC endpoints for testing MCP-style interactions.

  1. Features
    1. Quick Start
      1. REST Usage
        1. JSON-RPC Examples
          1. Environment Variables (DB)
            1. Run Tests
              1. Next Ideas

                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/ilyoungkim/mcp-test'

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