Connecting MCP Agents to 100s of Web Services
Project description
MCP Web Gateway
The MCP Web Gateway enables AI Agents to connect Web Services by accessing API directly.
- All HTTP endpoints are exposed as MCP resources with their original HTTP URLs.
- Generic REST tools (GET, POST, PUT, PATCH, DELETE) are provided for executing requests
This design changes the abstraction for the developers: instead of writing MCP servers, they write Web APIs using familiar REST semantics.
Installation
# Basic installation
pip install mcp-web-gateway
# With agent support for running autonomous agents
pip install mcp-web-gateway[agent]
# With development dependencies
pip install mcp-web-gateway[dev]
Quick Start
1. Direct FastAPI Integration
from fastapi import FastAPI
from mcp_web_gateway import McpWebGateway
# Your existing FastAPI app
app = FastAPI()
@app.get("/users")
async def list_users():
return [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]
@app.post("/users")
async def create_user(name: str):
return {"id": 3, "name": name}
# Create MCP gateway from FastAPI app
mcp = McpWebGateway.from_fastapi(
app,
httpx_client_kwargs={"base_url": "http://localhost:8000"}
)
1. Connecting through OpenAPI specs
from mcp_web_gateway import McpWebGateway
import httpx
import json
# Load your OpenAPI spec
with open("openapi.json") as f:
openapi_spec = json.load(f)
# Create HTTP client
client = httpx.AsyncClient(base_url="https://api.example.com")
# Create gateway server
gateway = McpWebGateway(openapi_spec, client)
# The gateway is now ready to be used by MCP clients!
3. Using the Gateway with an MCP Client
from fastmcp import Client
# Connect to the gateway
async with Client(gateway) as client:
# Discover available resources
resources = await client.list_resources()
# Example: ['https+get://api.example.com/users', 'https+post://api.example.com/users']
# Execute a GET request
users = await client.call_tool("GET", {
"url": "https+get://api.example.com/users"
})
# Execute a POST request
new_user = await client.call_tool("POST", {
"url": "https+post://api.example.com/users",
"body": {"name": "Charlie"}
})
Running the Server and Agent
Start the MCP Server
# Using the FastAPI example
fastmcp run -t streamable-http examples/fastapi_example.py
# The server will start on http://localhost:8000
# MCP endpoint will be available at http://localhost:8000/mcp/
Start an Autonomous Agent
# Ensure OPENAI_API_KEY is set in environment or fast-agent.secrets.yaml
export OPENAI_API_KEY=your-api-key
# Run the agent with the provided instructions
fast-agent go \
-i agent/instructions.md \
--url=http://127.0.0.1:8000/mcp/ \
--model=gpt-4.1-mini
The agent will:
- Connect to your MCP Web Gateway
- Discover available API endpoints
- Interact with users to understand their needs
- Execute API operations on their behalf
Web Agents
The agent/instructions.md file contains an initial set of instructions for LLM agents to:
- Discover available endpoints by checking
/,/llms.txt, and API documentation - Understand API structure through systematic exploration
- Execute operations following a clear methodology: Discover → Read → Understand → Plan → Execute → Validate
- Handle errors gracefully and learn from API responses
Advanced Usage
Custom HTTP Client Configuration
# Configure authentication, headers, etc.
client = httpx.AsyncClient(
base_url="https://api.example.com",
headers={"Authorization": "Bearer token"},
timeout=30.0
)
mcp = McpWebGateway(openapi_spec, client)
Examples
Check out the examples/ directory for:
fastapi_example.py- Complete FastAPI integration with a Todo API- More examples coming soon!
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/chughtapan/mcp-web-gateway
cd mcp-web-gateway
# Install with development dependencies
pip install -e ".[dev]"
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=mcp_web_gateway
# Run specific test file
pytest tests/unit/test_mcp_gateway.py -xvs
Code Quality
# Format code
black src/ tests/
isort src/ tests/
# Type checking
mypy src/
Acknowledgments
Built on top of the excellent FastMCP framework.
Note: This project is in active development.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_web_gateway-0.0.0.dev0.tar.gz.
File metadata
- Download URL: mcp_web_gateway-0.0.0.dev0.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce32b4e2572478d68054c513c4dfe7c252bf711dc6f99908d26a0a6e118227e5
|
|
| MD5 |
ac97e708bb7aea6a09163247c20ab04b
|
|
| BLAKE2b-256 |
70e867d748581ebd03c8db7ff09de7c92123de0dd31ac401fa9644f1c13e1620
|
Provenance
The following attestation bundles were made for mcp_web_gateway-0.0.0.dev0.tar.gz:
Publisher:
release.yml on chughtapan/mcp-web-gateway
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_web_gateway-0.0.0.dev0.tar.gz -
Subject digest:
ce32b4e2572478d68054c513c4dfe7c252bf711dc6f99908d26a0a6e118227e5 - Sigstore transparency entry: 347510979
- Sigstore integration time:
-
Permalink:
chughtapan/mcp-web-gateway@73a36af419530c0d01a1be9442c3c025f7685f27 -
Branch / Tag:
refs/tags/v0.0.0dev1 - Owner: https://github.com/chughtapan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@73a36af419530c0d01a1be9442c3c025f7685f27 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mcp_web_gateway-0.0.0.dev0-py3-none-any.whl.
File metadata
- Download URL: mcp_web_gateway-0.0.0.dev0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
005125bf8770ea35527219865bd43456b59c18f178b26052d4ac2d43faab6123
|
|
| MD5 |
fa56910041da9b68742c0768e9454a33
|
|
| BLAKE2b-256 |
319aa43e26d36edb0e2ef7f857a7e0b53549849376c2adda9b35bc35f0cf14bc
|
Provenance
The following attestation bundles were made for mcp_web_gateway-0.0.0.dev0-py3-none-any.whl:
Publisher:
release.yml on chughtapan/mcp-web-gateway
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_web_gateway-0.0.0.dev0-py3-none-any.whl -
Subject digest:
005125bf8770ea35527219865bd43456b59c18f178b26052d4ac2d43faab6123 - Sigstore transparency entry: 347510985
- Sigstore integration time:
-
Permalink:
chughtapan/mcp-web-gateway@73a36af419530c0d01a1be9442c3c025f7685f27 -
Branch / Tag:
refs/tags/v0.0.0dev1 - Owner: https://github.com/chughtapan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@73a36af419530c0d01a1be9442c3c025f7685f27 -
Trigger Event:
release
-
Statement type: