Skip to main content

MCPC - Model Context Protocol Callback

PyPI version License: MIT Python Versions

MCPC is an extension to MCP (Model-Context-Protocol) that solves a critical limitation in LLM tool interactions: enabling continued conversations while running tools background tasks. It facilitates asynchronous two-way communication between LLMs and tools through the already existing MCP transport - no additional transport layer needed, while maintaining full backward compatibility.

Conceptual demo of MCPC's continuous conversation flow between LLM and tools (UI not included)

What is MCPC?

MCPC is an extension to the MCP protocol, not a replacement. It builds upon the existing MCP infrastructure to add real-time two-way communication capabilities while maintaining full compatibility with standard MCP implementations.

MCPC solves a critical limitation in LLM tool interactions: enabling continuous two-way communication while running background tasks:

  • Bidirectional communication between LLMs and tools using the same MCP transport
  • Continuous conversation with LLMs during tool execution
  • Real-time updates from background processes
  • Asynchronous notifications when operations complete
  • Support for indefinitely running tasks with streaming updates

Compatibility Matrix

Features

Feature Status Notes
STDIO Transport ✅ Implemented Full support for standard input/output transport
SSE Transport ⚠️ Limited Support Standard MCP operations only, MCPC features pending
MCPC Client → Standard MCP Server ✅ Implemented Full backward compatibility
Standard MCP Client → MCPC Server ✅ Implemented Automatic fallback to synchronous results

Frameworks

Framework Status Notes
FastMCP 😎 ✅ Implemented Recommended
Standard MCP SDK Server ✅ Implemented Works (Use FastMCP if you can)

Quick Installation

# With UV (recommended)
uv add mcpc

# With pip
pip install mcpc

Basic Client Usage

# Initialize the MCPC handler
mcpc_handler = MCPCHandler("my-provider")

# Define your event listener function
async def my_mcpc_listener(mcpc_message: MCPCMessage) -> None:
    print(f"Received MCPC message: {mcpc_message}")
    # Handle the message based on status
    if mcpc_message.type == "task" and mcpc_message.event == "complete":
        print(f"Task {mcpc_message.task_id} completed with result: {mcpc_message.result}")

# Add your event listener for MCPC Message
mcpc_handler.add_event_listener(my_mcpc_listener)

# Wrap the transport with MCPC event listeners
wrapped_transport = await mcpc_handler.wrap_streams(*transport)

# Create a ClientSession with the wrapped transport
session = await ClientSession(*wrapped_transport)

# Initialize MCPC features by checking for MCPC support
mcpc_supported = await mcpc_handler.init_mcpc(session)
if mcpc_supported:
    print(f"MCPC protocol v{mcpc_handler.protocol_version} supported")

Basic Server Usage - FastMCP

# Initialize MCPC helper
server = FastMCP("my-provider")
mcpc = MCPCHelper(server)

@server.tool()
async def process_data(url: str) -> dict:
    async def process_data_task():
        yield mcpc.create_task_event(
            event="update",
            tool_name="process_data",
            session_id=session_id,
            task_id=task_id,
            result=f"Processing {url}..."
        ))
        await asyncio.sleep(3) # Simulate processing time
        yield mcpc.create_task_event(
            event="complete",
            tool_name="process_data",
            session_id=session_id,
            task_id=task_id,
            result={
                YOUR_DATA_OBJECT
            }
        )

    # Start a background task - or run synchronous if no MCPC support
    collected_messages = await mcpc.start_task(task_id, process_data_task)

    # For standard MCP clients, return collected complete/failed messages
    if collected_messages:
        # Keep in mind that FastMCP differs from Standard MCP
        # by expecting direct result rather than TextContent
        # It has implications in that it returns
        # all messages as "one" item, rather than multiple
        return collected_messages

    # For MCPC clients, return immediate acknowledgment
    # See comment above on why this is not [TextContent]
    return mcpc.create_task_event(
        event="created",
        tool_name="process_data",
        session_id=session_id,
        task_id=task_id,
        result=f"Started processing data_id={data_id}. Updates will stream in real-time."
    )

if __name__ == "__main__":
    asyncio.run(server.run())

Documentation

For detailed documentation, please see:

License

MIT

Metadata

Release files for mcpc 0.2.6

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

Source distribution (sdist)

Source distribution for mcpc 0.2.6
File Size Uploaded
mcpc-0.2.6.tar.gz 115.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcpc 0.2.6
File Interpreter ABI Platform
mcpc-0.2.6-py3-none-any.whl Python 3 none any Details

Total release size: 126.4 kB

Release files / mcpc-0.2.6.tar.gz

Download URL mcpc-0.2.6.tar.gz
Size 115.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a970c1d23f60c52f13d480f8a1a641ea2893d48905c0dad49536003db425a18e
BLAKE2b-256 checksum
How to use checksums
8e4ede9c3ca175b11b5d7e971e144573dcdff40001b4f456251f760289d9a3fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Apr 3, 2025.

Transparency log

Release files / mcpc-0.2.6-py3-none-any.whl

Download URL mcpc-0.2.6-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b150e4baee08c5f6f28b192e613e62b221f1e4c2416a5e309622f8ead1a134b
BLAKE2b-256 checksum
How to use checksums
93f7063a65f3d8608e29e23beb71d0cc35ea3462962a20e71ed4b0519f51ab91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Apr 3, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.6 This release

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release 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