Skip to main content

UTCP MCP Plugin

PyPI Downloads

Model Context Protocol (MCP) interoperability plugin for UTCP, enabling seamless integration with existing MCP servers.

Features

  • MCP Server Integration: Connect to existing MCP servers
  • Stdio Transport: Local process-based MCP servers
  • HTTP Transport: Remote MCP server connections
  • OAuth2 Authentication: Secure authentication for HTTP servers
  • Migration Support: Gradual migration from MCP to UTCP
  • Tool Discovery: Automatic tool enumeration from MCP servers
  • Session Management: Efficient connection handling

Installation

pip install utcp-mcp

Quick Start

from utcp.utcp_client import UtcpClient

# Connect to MCP server
client = await UtcpClient.create(config={
    "manual_call_templates": [{
        "name": "mcp_server",
        "call_template_type": "mcp",
        "config": {
            "mcpServers": {
                "filesystem": {
                    "command": "node",
                    "args": ["mcp-server.js"]
                }
            }
        }
    }]
})

# Call MCP tool through UTCP
result = await client.call_tool("mcp_server.filesystem.read_file", {
    "path": "/data/file.txt"
})

Configuration Examples

Stdio Transport (Local Process)

{
  "name": "local_mcp",
  "call_template_type": "mcp",
  "config": {
    "mcpServers": {
      "filesystem": {
        "command": "python",
        "args": ["-m", "mcp_filesystem_server"],
        "env": {"LOG_LEVEL": "INFO"}
      }
    }
  }
}

HTTP Transport (Remote Server)

{
  "name": "remote_mcp",
  "call_template_type": "mcp",
  "config": {
    "mcpServers": {
      "api_server": {
        "transport": "http",
        "url": "https://mcp.example.com"
      }
    }
  }
}

With OAuth2 Authentication

{
  "name": "secure_mcp",
  "call_template_type": "mcp",
  "config": {
    "mcpServers": {
      "secure_server": {
        "transport": "http",
        "url": "https://mcp.example.com"
      }
    }
  },
  "auth": {
    "auth_type": "oauth2",
    "token_url": "https://auth.example.com/token",
    "client_id": "${CLIENT_ID}",
    "client_secret": "${CLIENT_SECRET}",
    "scope": "read:tools"
  }
}

Multiple MCP Servers

{
  "name": "multi_mcp",
  "call_template_type": "mcp",
  "config": {
    "mcpServers": {
      "filesystem": {
        "command": "python",
        "args": ["-m", "mcp_filesystem"]
      },
      "database": {
        "command": "node",
        "args": ["mcp-db-server.js"],
        "cwd": "/app/mcp-servers"
      }
    }
  }
}

Migration Scenarios

Gradual Migration from MCP to UTCP

Phase 1: MCP Integration

# Use existing MCP servers through UTCP
client = await UtcpClient.create(config={
    "manual_call_templates": [{
        "name": "legacy_mcp",
        "call_template_type": "mcp",
        "config": {"mcpServers": {"server": {...}}}
    }]
})

Phase 2: Mixed Environment

# Mix MCP and native UTCP tools
client = await UtcpClient.create(config={
    "manual_call_templates": [
        {
            "name": "legacy_mcp",
            "call_template_type": "mcp",
            "config": {"mcpServers": {"old_server": {...}}}
        },
        {
            "name": "new_api",
            "call_template_type": "http",
            "url": "https://api.example.com/utcp"
        }
    ]
})

Phase 3: Full UTCP

# Pure UTCP implementation
client = await UtcpClient.create(config={
    "manual_call_templates": [{
        "name": "native_utcp",
        "call_template_type": "http",
        "url": "https://api.example.com/utcp"
    }]
})

Debugging and Troubleshooting

Enable Debug Logging

import logging
logging.getLogger('utcp.mcp').setLevel(logging.DEBUG)

try:
    client = await UtcpClient.create(config=mcp_config)
    tools = await client.list_tools()
except TimeoutError:
    print("MCP server connection timed out")

Child Process stderr

Stdio MCP servers often write banners, telemetry notices and auth chatter to stderr, multiplied by every server you federate. utcp-mcp therefore discards the child's stderr by default. To see it while debugging a server that fails to start, opt back in for the host process:

UTCP_MCP_CHILD_STDERR=inherit python your_app.py

Any other value, or leaving the variable unset, keeps stderr suppressed. When a stdio server fails to connect, the error log reminds you of this switch.

List Available Tools

# Discover tools from MCP server
tools = await client.list_tools()
print(f"Available tools: {[tool.name for tool in tools]}")

Connection Testing

@pytest.mark.asyncio
async def test_mcp_integration():
    client = await UtcpClient.create(config={
        "manual_call_templates": [{
            "name": "test_mcp",
            "call_template_type": "mcp",
            "config": {
                "mcpServers": {
                    "test": {
                        "command": "python",
                        "args": ["-m", "test_mcp_server"]
                    }
                }
            }
        }]
    })
    
    tools = await client.list_tools()
    assert len(tools) > 0
    
    result = await client.call_tool("test_mcp.echo", {"message": "test"})
    assert result["message"] == "test"

Error Handling

from utcp.exceptions import ToolCallError

try:
    result = await client.call_tool("mcp_server.tool", {"arg": "value"})
except ToolCallError as e:
    print(f"MCP tool call failed: {e}")
    # Check if it's a connection issue, authentication error, etc.

Performance Considerations

  • Session Reuse: MCP plugin reuses connections when possible
  • Timeout Configuration: Set appropriate timeouts for MCP operations
  • Resource Cleanup: Sessions are automatically cleaned up
  • Concurrent Calls: Multiple tools can be called concurrently

Related Documentation

Examples

For complete examples, see the UTCP examples repository.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

utcp_mcp-1.1.4.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

utcp_mcp-1.1.4-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file utcp_mcp-1.1.4.tar.gz.

File metadata

  • Download URL: utcp_mcp-1.1.4.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for utcp_mcp-1.1.4.tar.gz
Algorithm Hash digest
SHA256 c61de81bd6c19b21cf0d8c568c1f6d0dff316dd054fd2f95601f3dec038ec998
MD5 e4c2a51dd8d3c580518b4e5482aea43f
BLAKE2b-256 02a4e7bbf316e77666b7de87925d11b6880b707214475506a160d370e5740f80

See more details on using hashes here.

File details

Details for the file utcp_mcp-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: utcp_mcp-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for utcp_mcp-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fc17667218c2e66aa5e4accb43d80eb46d554ca694e50147e5cdfc775076a709
MD5 2d3d7ffc5762e410dfec5dc170ad9159
BLAKE2b-256 af5840440ad2d991b146cad5229f836da4fc5b5f43282c5b8b7f9108d7c17b35

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.4 This release

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page