Skip to main content

Model Context Protocol with SLIM as transport

Project description

SLIM-MCP Integration

Leverage SLIM as a transport mechanism for MCP, enabling efficient load balancing and dynamic discovery across MCP servers.

Installation

pip install slim-mcp

Overview

SLIM-MCP provides a seamless integration between SLIM (Secure Low-Latency Interactive Messaging) and MCP (Model Context Protocol), allowing you to:

  • Create MCP servers that can be discovered and accessed through SLIM
  • Connect MCP clients to servers using SLIM as the transport layer
  • Handle multiple concurrent sessions
  • Leverage SLIM's load balancing and service discovery capabilities

Usage

Server Setup

from slim_mcp import SLIMServer
import mcp.types as types
from mcp.server.lowlevel import Server

# Create an MCP server application
app = Server("example-server")

# Define your tools
example_tool = types.Tool(
    name="example",
    description="An example tool",
    inputSchema={
        "type": "object",
        "required": ["url"],
        "properties": {
            "url": {
                "type": "string",
                "description": "example URL input parameter",
            }
        },
    },
)

@app.list_tools()
async def list_tools() -> list[types.Tool]:
    return [example_tool]

# Configure and start the SLIM server
config = {
    "endpoint": "http://127.0.0.1:12345",
    "tls": {
        "insecure": True,
    },
}

async with SLIMServer(config, "org", "namespace", "server-name") as slim_server:
    # Handle incoming sessions
    async for session in slim_server:
        async with slim_server.new_streams(session) as streams:
            await app.run(
                streams[0],
                streams[1],
                app.create_initialization_options(),
            )

Client Setup

from slim_mcp import SLIMClient

# Configure the client
config = {
    "endpoint": "http://127.0.0.1:12345",
    "tls": {
        "insecure": True,
    },
}

async with SLIMClient(
    config,
    "org",
    "namespace",
    "client-id",
    "org",
    "namespace",
    "server-name"
) as client:
    async with client.to_mcp_session() as mcp_session:
        # Initialize the session
        await mcp_session.initialize()

        # List available tools
        tools = await mcp_session.list_tools()

        # Print the available tools
        print(f"Available tools: {tools}")

Features

  • Automatic Reconnection: SLIM automatically handles reconnection to the server if the connection is lost
  • Concurrent Sessions: Support for multiple concurrent sessions with proper resource management
  • TLS Support: Built-in support for secure TLS connections
  • Dynamic Discovery: Leverage SLIM's service discovery capabilities to find and connect to MCP servers
  • Load Balancing: Utilize SLIM's load balancing features for optimal server distribution

Configuration

The configuration object supports the following options:

config = {
    "endpoint": "http://127.0.0.1:12345",  # Server endpoint
    "tls": {
        "insecure": True,  # Set to False for production
        # Add other TLS options as needed
    },
}

Error Handling

The library provides comprehensive error handling and logging. All operations are wrapped in try-except blocks to ensure proper cleanup of resources.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

Apache-2.0

Project details


Download files

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

Source Distribution

slim_mcp-0.1.8.tar.gz (150.4 kB view details)

Uploaded Source

Built Distribution

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

slim_mcp-0.1.8-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file slim_mcp-0.1.8.tar.gz.

File metadata

  • Download URL: slim_mcp-0.1.8.tar.gz
  • Upload date:
  • Size: 150.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slim_mcp-0.1.8.tar.gz
Algorithm Hash digest
SHA256 f878b8691750be8d0b0f46a9cf00c4048b7e97eff37f1151da8dd370459fe1b0
MD5 291dd8591c13a5698841102d43a5d2a2
BLAKE2b-256 eebcc1e15f04c2eb2596851bee040160ba63f933c82d4e2f1d5e90b23171f2bd

See more details on using hashes here.

File details

Details for the file slim_mcp-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: slim_mcp-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slim_mcp-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c8e666eb1efd7dc6a0b4a4d93276ccd05f8e8b9f77d5d729d76184b4789d391e
MD5 a4821f8f97967452da32ff02c0d9fe65
BLAKE2b-256 c66ae38d8cf3e29f1deeb2cd2d792ca1b3a946859359509768868c5781590735

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page