AWS Model Context Protocol (MCP) Server

1.3.29 · active · verified Sun Apr 12

The AWS API Model Context Protocol (MCP) Server provides a Python implementation of the gRPC-based Model Context Protocol. It allows an external client to provide API models and context to the server, assisting in API construction. It is currently at version 1.3.29 and receives regular updates, primarily for patch and minor feature releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic MCP server using `awslabs-aws-api-mcp-server`. It implements a custom `ModelContextServiceServicer` and starts an asynchronous gRPC server. In a real application, you would implement the `AddContext` and `GetContext` methods to handle actual model context operations.

import asyncio
from concurrent import futures
import grpc

from mcp.server import McpServer
from mcp.service import ModelContextServiceServicer
from mcp.server.models.mcp_pb2_grpc import add_ModelContextServiceServicer_to_server
from mcp.server.models.mcp_pb2 import AddContextRequest, AddContextResponse

class MyMcpService(ModelContextServiceServicer):
    """Example implementation of the ModelContextServiceServicer."""
    async def AddContext(self, request: AddContextRequest, context: grpc.aio.ServicerContext) -> AddContextResponse:
        print(f"Received AddContext request for model: {request.model_name}")
        # Implement actual context logic here
        return AddContextResponse(success=True, message="Context added successfully")

    async def GetContext(self, request, context):
        # Implement GetContext logic
        return super().GetContext(request, context)

async def serve():
    server = grpc.aio.server(futures.ThreadPoolExecutor(max_workers=10))
    add_ModelContextServiceServicer_to_server(MyMcpService(), server)
    server.add_insecure_port('[::]:50051')
    print('Starting MCP server on port 50051')
    await server.start()
    await server.wait_for_termination()

if __name__ == '__main__':
    asyncio.run(serve())

view raw JSON →