This package is a small helper module that lets you define and consume multiple MCP servers (stdio, SSE, or Streamable HTTP) from a JSON configuration. It uses `pydantic-ai` MCP clients and validates configuration with Pydantic models.
Project description
MCPLoader
MCPLoader is a small helper module that lets you define and consume multiple MCP servers (stdio, SSE, or Streamable HTTP) from a JSON configuration. It uses pydantic-ai MCP clients and validates configuration with Pydantic models.
Features
- HTTP (SSE / Streamable HTTP) and STDIO server types
- Configuration validation with Pydantic
- Multiple MCP servers from a single JSON file
- Simple Python API: pass a config path, get ready-to-use server clients
Installation
Use it as a module inside your own codebase. Required dependencies:
pip install mcploader
or
uv add mcploader
Quick start
from mcploader import MCPServerManager
# Provide your configuration file path (e.g., config/http.json or data/mcp/http.json)
manager = MCPServerManager("config/http.json")
servers = manager.servers # serialized list of MCPServer
from pydantic_ai import Agent
agent = Agent('openai:gpt-4o', toolsets=servers)
async def main():
async with agent:
await agent.run('Ask something here...')
import asyncio
if __name__ == '__main__':
asyncio.run(main())
Configuration
Configuration is a JSON object with a root key mcpServers. Each key under mcpServers is a server name; the value is its configuration.
General schema
{
"mcpServers": {
"<serverName>": { ... }
}
}
Each server can be one of two forms:
- STDIO:
StdioServerParameters - HTTP:
ServerParameters(contains atransportbody)
HTTP (SSE / Streamable HTTP) example
{
"mcpServers": {
"server1": {
"transport": {
"type": "streamable-http", // or "sse"
"url": "http://127.0.0.1:8000/mcp",
"headers": {
"Authorization": "Bearer your-token-here",
"Content-Type": "application/json",
"User-Agent": "Claude-Desktop/1.0",
"X-API-Version": "v1"
},
"timeout": 30000,
"readTimeout": 300000,
"maxRetries": 5
}
}
}
}
type is normalized to lowercase and must be one of:
ssestreamable-http
STDIO example
{
"mcpServers": {
"server1": {
"command": "deno",
"args": ["run", "-N", "-R=node_modules", "-W=node_modules", "--node-modules-dir=auto", "jsr:@pydantic/mcp-run-python", "stdio"],
"env": { "OPENAI_API_KEY": "..." },
"cwd": "/usr/path/to",
"timeout": 10,
"readTimeout": 300,
"maxRetries": 3
}
}
}
Fields and types (summary)
- HTTP (ServerParameters.transport: ServerBody)
- type:
"sse" | "streamable-http" - url: a valid URL
- headers:
dict[str, str](optional) - timeout: request timeout in ms (default 30000)
- readTimeout: read timeout in ms (default 300000)
- maxRetries: retry count (default 5)
- type:
- STDIO (StdioServerParameters)
- command: command to execute (e.g.,
deno,python) - args: command arguments (list)
- env: environment variables (key/value)
- cwd: working directory (optional)
- timeout: timeout in seconds (default 30)
- readTimeout: read timeout in seconds (default 300)
- maxRetries: retry count (default 1)
- command: command to execute (e.g.,
Note:
ServerParameters.server_typedefaults to"http",StdioServerParameters.server_typedefaults to"io". These are used internally to select the proper client.
Folder layout
This repository includes sample configurations under data/.
-
data/http.json: Streamable HTTP example -
data/sse.json: SSE example -
data/stdio.json: STDIO example -
Passing paths: Provide the absolute/relative path directly to
MCPServerManager, e.g.,MCPServerManager("data/mcp/http.json"). -
Schema: JSON files under
data/use the same schema; the root must havemcpServers, each key defining a server. -
Environment variants: You can create
data/mcp/prod/http.json,data/mcp/dev/http.json, etc., and select the appropriate file at runtime.
API surface
MCPServerManager(config_path: str): Reads the JSON config and validates it withServerConfig.MCPServerManager.servers -> list[MCPServer]: On first access, creates MCP clients (MCPServerSSE,MCPServerStreamableHTTP,MCPServerStdio) according to the config and caches them.
Feel free to reach me from contact@tomris.dev or my GitHub address.
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 mcploader-0.1.0.tar.gz.
File metadata
- Download URL: mcploader-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5697427786c281092e49d6bce6a7a77295e62c52f427ae8ebdf46683ae01fe86
|
|
| MD5 |
6b3c16bab658cf8a2e1c0604ff07411c
|
|
| BLAKE2b-256 |
1f31699cbbd1dc8133a56dfd8b66486a460147e45bda430b8b931d8e68dd4907
|
File details
Details for the file mcploader-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcploader-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfc93d47aafa164c13a36a82beaa069715db2641968dca699b6c54861d620ea7
|
|
| MD5 |
ca2afdfadcc4bf26364e7ba5cb01a0c8
|
|
| BLAKE2b-256 |
d0a3927c9d3a7b252c7882599af5720c1d9935faa05d90fbe558fa79f86b7db7
|