MCP from Config

Reuse mcpServers config from Claude Code, Cursor, VS Code, Gemini CLI, Codex, or PraisonAI YAML in one line

Paste the mcpServers block you already have in Claude Code, Cursor, VS Code, Gemini CLI, Codex, or PraisonAI YAML, and give its tools to an agent. You don’t need to rewrite it as MCP(command=..., args=...).

python
from praisonaiagents import Agent, MCP
from praisonaiagents.mcp import parse_mcp_servers

# The same mcpServers block you would paste from Claude Code / Cursor
config = {
    "mcpServers": {
        "filesystem": {
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
        }
    }
}

servers = parse_mcp_servers(config)
fs = MCP.from_config(servers["filesystem"], name="filesystem")

agent = Agent(
    name="FileAgent",
    instructions="You can read and write files.",
    tools=fs,
)
agent.start("List files in /tmp.")
Diagram

MCP from Config

📝 Editor config
mcpServers / servers / mcp.servers

⚙️ parse_mcp_servers

🔌 MCP.from_config

🤖 Agent

Which config shapes are accepted?

Diagram

Claude Code / Cline / Cursor

VS Code

Gemini CLI

Codex

PraisonAI YAML

Bare mapping

Where is your
MCP config from?

mcpServers: {…}

servers: {…}

mcpServers with
httpUrl, includeTools

mcp_servers with
bearer_token_env_var,
http_headers, tool_timeout_sec

mcp:
servers: {…}

{name: entry}

parse_mcp_servers

parse_mcp_servers looks for the servers under mcpServers, servers, mcp_servers, or mcp.servers, in that order. If none of these keys holds a mapping, it treats the whole dict as {name: entry}. An entry can also be a plain command string, such as {"fs": "npx -y @modelcontextprotocol/server-filesystem /tmp"}.

Quick Start

  1. Paste an editor config
    python
    from praisonaiagents import Agent, MCP
    from praisonaiagents.mcp import parse_mcp_servers
    
    servers = parse_mcp_servers({
        "mcpServers": {
            "fs": {"command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]}
        }
    })
    agent = Agent(tools=MCP.from_config(servers["fs"], name="fs"))
    agent.start("List files in /tmp.")
  2. Load every server at once
    python
    from praisonaiagents import Agent, MCP
    from praisonaiagents.mcp import parse_mcp_servers
    
    servers = parse_mcp_servers(config)
    agent = Agent(tools=[MCP.from_config(entry, name=name) for name, entry in servers.items()])
  3. Expand ${VAR} from the environment
    python
    from praisonaiagents import MCP
    
    mcp = MCP.from_config(
        {"url": "https://api.example.com/mcp", "headers": {"Authorization": "Bearer ${GITHUB_TOKEN}"}},
        name="github",
        expand_env=True,  # expands ${VAR}, ${env:VAR}, ${VAR:-default}
    )
  4. Codex-style bearer token
    python
    from praisonaiagents import MCP
    from praisonaiagents.mcp import parse_mcp_servers
    
    servers = parse_mcp_servers({
        "mcp_servers": {
            "sentry": {
                "url": "https://sentry.io/mcp",
                "bearer_token_env_var": "SENTRY_TOKEN",  # → Authorization: Bearer ${SENTRY_TOKEN}
                "tool_timeout_sec": 45,
            }
        }
    })
    mcp = MCP.from_config(servers["sentry"], name="sentry", expand_env=True)

How It Works

Diagram
MCP clientMCP.from_configparse_mcp_serversUserMCP clientMCP.from_configparse_mcp_serversUserconfig dict (any editor shape){name: normalised entry}entry (+ expand_env?)expand ${VAR} if askedcheck url is http(s)/ws(s)construct MCP(…)tools ready

parse_mcp_servers only changes the shape of the config. It leaves ${VAR} exactly as written. MCP.from_config builds the client, and it also accepts a raw editor entry, so you can skip parse_mcp_servers when you only have one server.

Field mapping

Editor fieldNormalised to
httpUrl, server_urlurl
http_headersheaders
bearer_token_env_var: VARadds Authorization: Bearer ${VAR} to headers
includeTools, enabled_tools, include_tools, tool_filterallowed_tools
excludeTools, exclude_toolsdisabled_tools
auth, oauth (client_id / clientId / CLIENT_ID, scopes)oauth: {client_id, scopes}
transporttype
tool_timeout_sectimeout
disabled: trueenabled: false
type valueNormalised to
localstdio
remote, streamable-http, streamable_http, streamableHttphttp
websocketws
(missing)stdio without a url, ws for ws:///wss://, sse for URLs ending in /sse, otherwise http

The fields name, description, trust, alwaysAllow, autoApprove, and startup_timeout_sec are dropped without a warning. Any other unknown field is dropped and a warning is logged.

Normalised entry

FieldTypeNotes
typestrstdio, http, sse, or ws
commandstr or liststdio only. In a list such as ["npx", "-y", "pkg"], the first item is the command and the rest go before args
argslist[str]stdio only
envdict[str, str]stdio only
cwdstrstdio only
urlstrMust be http(s):// or ws(s)://
headersdict[str, str]Remote servers only
oauthdictParsed, but the client does not use it yet. A warning is logged
allowed_toolslist[str]Only these tools are exposed
disabled_toolslist[str]These tools are hidden
timeoutfloatSeconds. Values of 1000 or more are treated as milliseconds
enabledboolIf False, MCP.from_config raises an error

MCP.from_config parameters

ParameterTypeDefaultDescription
entrydict or str—One server entry, either normalised or raw from an editor
namestr"server"Server name used in errors and logs
expand_envboolFalseExpand ${VAR}, ${env:VAR}, and ${VAR:-default}. A missing variable with no default raises ValueError

Safety behaviour

Common Patterns

Import a Claude Code project config
python
import json
from praisonaiagents import Agent, MCP
from praisonaiagents.mcp import parse_mcp_servers

with open(".mcp.json") as f:
    servers = parse_mcp_servers(json.load(f))

agent = Agent(
    name="Assistant",
    tools=[MCP.from_config(entry, name=name) for name, entry in servers.items() if entry.get("enabled", True)],
)
PraisonAI YAML mcp.servers block
python
import yaml
from praisonaiagents import Agent, MCP
from praisonaiagents.mcp import parse_mcp_servers

config = yaml.safe_load("""
mcp:
  servers:
    time:
      command: uvx
      args: [mcp-server-time]
""")

servers = parse_mcp_servers(config)
agent = Agent(tools=MCP.from_config(servers["time"], name="time"))
agent.start("What time is it in Tokyo?")
Filter tools with Gemini CLI fields
python
from praisonaiagents import Agent, MCP

mcp = MCP.from_config(
    {"httpUrl": "https://api.example.com/mcp", "includeTools": ["search"]},
    name="search",
)
agent = Agent(tools=mcp)

Best Practices

Keep secrets as ${VAR}

Write tokens as ${VAR} in your config and pass expand_env=True. That way the secret stays out of the config file.

Prefer streamable HTTP for authenticated servers

Legacy SSE cannot send headers. Use a Streamable HTTP URL, or set "type": "streamable-http".

Name each server

Pass name= so that errors and warnings tell you which server failed.

Related