Skip to main content

ModuleContextStreaming (MCS) 🚀

PyPI Pytest License Python Version

A high-performance gRPC service designed to provide real-time, streamable context to Large Language Models (LLMs). This project serves as a robust backend for AI applications that require secure, low-latency communication with server-side tools and resources.

It features a secure, authenticated API and a powerful adapter for integrating with Model Context Protocol (MCP) servers, allowing you to expose tools from any MCP-compatible backend through a single, unified gRPC interface.


Why Use MCS?

  • Solve LLM Latency: Traditional REST APIs can be slow for conversational AI. MCS uses gRPC streaming to send data back to the LLM as it's generated, creating a more responsive user experience.
  • Unify Your Tools: Stop building one-off backends. MCS can act as a secure gateway to all your tools, whether they are native Python functions or external Model Context Protocol (MCP) servers.
  • Secure by Default: Don't worry about boilerplate security code. MCS provides out-of-the-box JWT authentication via Keycloak and enforces TLS encryption.
  • Type-Safe & Reliable: By using a Protobuf schema, you eliminate entire classes of bugs. The API contract is clear, versionable, and reliable.

High-Level Architecture

High-Level Architecture


Features

  • High-Performance Streaming: Built on gRPC and HTTP/2 for efficient, multiplexed, and low-latency data streaming.
  • Strict API Contract: Uses Protocol Buffers (.proto) as the single source of truth for the API, ensuring type-safe communication.
  • Secure by Default:
    • JWT Authentication: Integrates with Keycloak for robust, token-based authentication using a gRPC interceptor.
    • TLS Encryption: Supports secure gRPC channels out-of-the-box for encrypted client-server communication.
  • MCP Backend Integration: Seamlessly connect to and expose tools from MCP servers running over stdio.
  • Intelligent Client: Includes an MCP-aware parser that can automatically distinguish between text, images, structured JSON, resources, and errors from tool responses.
  • Configurable & Extensible: The server and client are configured via environment variables (.env file) and the server's Tool Registry makes it simple to add new native Python tools.

Project Structure

ModuleContextStreaming/         # The project root directory
├── ModuleContextStreaming/     # The main, installable Python package
│   ├── init.py
│   ├── server.py             # Reusable gRPC Server class with MCP adapter
│   ├── client.py             # Reusable gRPC Client class with MCP parser
│   ├── auth.py               # Keycloak JWT authentication interceptor
│   ├── exceptions.py         # Custom exception types
│   ├── mcs_pb2.py            # Generated Protobuf messages
│   └── mcs_pb2_grpc.py       # Generated gRPC client/server stubs
├── protos/
│   └── mcs.proto             # The API contract source of truth
├── examples/
│   ├── simple_server.py      # Example runnable server with native tools
│   └── simple_client.py      # Example runnable client
├── certs/
│   ├── private.key           # Placeholder for your TLS private key
│   └── certificate.pem       # Placeholder for your TLS certificate
├── build_scripts.py          # Script to generate and patch gRPC code
├── DESIGN.md                 # Project architecture and design decisions
├── pyproject.toml            # Project metadata and dependencies
└── README.md

Setup and Installation

Prerequisites

  • Python 3.10+
  • Git
  • (Optional) OpenSSL - for self-signed certificates

Installation Steps

  1. Clone the repository:

    git clone [https://github.com/armstrongsam25/ModuleContextStreaming.git](https://github.com/armstrongsam25/ModuleContextStreaming.git)
    cd ModuleContextStreaming
    
  2. Create and activate a virtual environment:

    python -m venv .venv
    
    # On Windows: 
    .\.venv\Scripts\activate
    
    # On macOS/Linux: 
    source .venv/bin/activate
    
  3. Install dependencies: This installs the project in editable mode (-e) along with all development dependencies.

    pip install -e .[dev]
    
  4. Generate gRPC Code: Run these commands to compile the .proto file and apply the necessary import patch. You only need to re-run this when protos/mcs.proto changes.

    # 1. Generate gRPC code from the .proto file
    python -m grpc_tools.protoc -I ./protos --python_out=./ModuleContextStreaming --grpc_python_out=./ModuleContextStreaming mcs.proto
    
    # 2. Patch the generated code for correct relative imports
    python build_scripts/build.py
    
  5. Generate Self-Signed Certificates (for local testing):

    openssl req -x509 -newkey rsa:4096 -keyout certs/private.key -out certs/certificate.pem -sha256 -days 365 -nodes -subj "/CN=localhost"
    

Usage

  1. Configure your environment: Copy .env.example to .env and fill in your Keycloak details.
  2. Start the Server: In your first terminal, run:
    python examples/simple_server.py
    
  3. Run the Client: In a second terminal, run:
    python examples/simple_client.py
    

Contributing

Contributions are welcome! Please feel free to open an issue to report a bug or request a feature, or submit a pull request.


Roadmap

  • Advanced Authorization: Implement role-based access control (RBAC) based on JWT claims.
  • TCP-based MCP Backends: Extend the MCPToolAdapter to support TCP sockets.
  • Enhanced Observability: Integrate structured logging and OpenTelemetry.
  • Comprehensive Testing: Add a full suite of unit and integration tests.
  • PyPI Packaging: Finalize packaging and publish to PyPI.

License

Distributed under the MIT License.

Metadata

Release files for ModuleContextStreaming 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ModuleContextStreaming 0.0.7
File Size Uploaded Provenance Actions
modulecontextstreaming-0.0.7.tar.gz 21.6 kB With provenance Details for modulecontextstreaming-0.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ModuleContextStreaming 0.0.7
File Interpreter ABI Platform Actions
modulecontextstreaming-0.0.7-py3-none-any.whl Python 3 none any Details for modulecontextstreaming-0.0.7-py3-none-any.whl

Total release size: 44.7 kB

Release files / modulecontextstreaming-0.0.7.tar.gz

Download URL modulecontextstreaming-0.0.7.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e5a2bd4b377c4b517e0a55d942acc3215dbd21d81ad86960c2170cee9fb98a45
BLAKE2b-256 checksum
How to use checksums
ce625151c0a1df567fb05f717c2943f7da4a176083741575419d6c97c12f5566
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2025.

Transparency log

Release files / modulecontextstreaming-0.0.7-py3-none-any.whl

Download URL modulecontextstreaming-0.0.7-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71db2575b9287a8f38f9a8c7b7c6d74439a1bdf8b4ced7fa13b3ea0c216f2273
BLAKE2b-256 checksum
How to use checksums
a9d70528a660e78d8bb15e1cd043cb0ce663b854764ea2ce33046ab2dad09639
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2025.

Transparency log

Security for ModuleContextStreaming 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for modulecontextstreaming-0.0.7.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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