AWS Labs Core Model Context Protocol Server

1.0.27 · active · verified Fri Apr 17

The `awslabs-core-mcp-server` library provides a Python implementation of an AWS Labs Model Context Protocol (MCP) server. It allows for the creation of in-memory MCP servers, facilitating communication and context management for models over WebSockets. The current version is 1.0.27, and releases appear to be driven by the needs of the broader MCP project rather than a fixed schedule.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate and run an in-memory Model Context Protocol (MCP) server using `asyncio` and `websockets`. The server will listen for WebSocket connections and handle MCP requests. The `initial_data` argument is optional and can be used to pre-populate the server's context.

import asyncio
import websockets
from awslabs_core_mcp_server.model_context_protocol import InMemoryModelContextProtocolServer

async def run_server():
    # Example initial data (can be empty or loaded from a file)
    initial_data = {
        "context_id_1": {"model_id": "model_A", "context": {"key": "value"}}
    }
    
    # Initialize the in-memory MCP server with optional initial data
    server_instance = InMemoryModelContextProtocolServer(initial_data=initial_data)
    
    # Start the WebSocket server
    port = 8080
    host = "localhost"
    print(f"Starting MCP server on ws://{host}:{port}")
    async with websockets.serve(server_instance.handle_request, host, port):
        await asyncio.Future() # Run forever

if __name__ == "__main__":
    try:
        asyncio.run(run_server())
    except KeyboardInterrupt:
        print("\nServer stopped gracefully.")

view raw JSON →