Metadata-Version: 2.4
Name: coreason_mcp
Version: 0.4.0
Summary: Standardizes external data access using the Model Context Protocol.
License: # The Prosperity Public License 3.0.0
         
         Contributor: CoReason, Inc.
         
         Source Code: https://github.com/CoReason-AI/coreason_mcp
         
         ## Purpose
         
         This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
         
         ## Agreement
         
         In order to receive this license, you have to agree to its rules.  Those rules are both obligations under that agreement and conditions to your license.  Don't do anything with this software that triggers a rule you can't or won't follow.
         
         ## Notices
         
         Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
         
         ## Commercial Trial
         
         Limit your use of this software for commercial purposes to a thirty-day trial period.  If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
         
         ## Contributions Back
         
         Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
         
         ## Personal Uses
         
         Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
         
         ## Noncommercial Organizations
         
         Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
         
         ## Defense
         
         Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
         
         ## Copyright
         
         The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
         
         ## Patent
         
         The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
         
         ## Reliability
         
         The contributor can't revoke this license.
         
         ## Excuse
         
         You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
         
         ## No Liability
         
         ***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
License-File: LICENSE
License-File: NOTICE
Author: Gowtham A Rao
Author-email: gowtham.rao@coreason.ai
Requires-Python: >=3.11
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Dist: aiofiles (>=23.2.1,<24.0.0)
Requires-Dist: anyio (>=4.12.1,<5.0.0)
Requires-Dist: httpx (>=0.28.1,<0.29.0)
Requires-Dist: jsonschema (>=4.25.1,<5.0.0)
Requires-Dist: loguru (>=0.7.2,<0.8.0)
Requires-Dist: mcp (>=1.25.0,<2.0.0)
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
Project-URL: Documentation, https://github.com/CoReason-AI/coreason_mcp
Project-URL: Homepage, https://github.com/CoReason-AI/coreason_mcp
Project-URL: Repository, https://github.com/CoReason-AI/coreason_mcp
Description-Content-Type: text/markdown

# coreason-mcp

The Complete Gateway for the Model Context Protocol (MCP).

`coreason-mcp` serves as the **Universal Interface Layer** for the CoReason ecosystem. It replaces ad-hoc API wrappers with a standardized **Model Context Protocol (MCP)** Gateway, acting as an **MCP Host** that connects to both remote services (via SSE) and local sidecars (via Stdio).

[![Organization](https://img.shields.io/badge/organization-CoReason--AI-blue)](https://github.com/CoReason-AI)
[![License](https://img.shields.io/badge/license-Prosperity%203.0-blue)](https://img.shields.io/badge/license-Prosperity%203.0-blue)
[![Build Status](https://github.com/CoReason-AI/coreason-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/CoReason-AI/coreason-mcp/actions)
[![Code Style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)
[![Documentation](https://img.shields.io/badge/docs-Product%20Requirements-green)](docs/product_requirements.md)

## Installation

```bash
pip install coreason-mcp
```

## Features

*   **Hybrid Transport:** Support for both **SSE** (remote microservices) and **Stdio** (local sidecars) transports.
*   **Tool Aggregation:** Merges tools from multiple servers into a unified namespace with automatic conflict resolution.
*   **Secure Credential Injection:** Manages API keys and headers securely in the transport layer, keeping them out of the agent's context.
*   **Async/High Concurrency:** Built on `httpx` and `asyncio` to ensure non-blocking operations across the mesh.
*   **Robust Error Handling:** Maps connection and protocol errors to standardized exceptions.

For detailed requirements and architecture, see [Product Requirements](docs/product_requirements.md).

## Usage

Here is how to initialize and use the library to connect to a local filesystem tool and a remote database.

```python
import asyncio
from coreason_mcp.config import McpServerConfig, TransportType
from coreason_mcp.manager import McpManager

# 1. Configure your servers (Mesh Topology)
# A local sidecar (Stdio) - e.g., for secure filesystem access
local_fs = McpServerConfig(
    name="local_fs",
    transport=TransportType.STDIO,
    command="npx",
    args=["-y", "@modelcontextprotocol/server-filesystem", "/home/user/docs"]
)

# A remote microservice (SSE) - e.g., for clinical data
clinical_db = McpServerConfig(
    name="clinical_db",
    transport=TransportType.SSE,
    url="http://db-service.internal:8080/sse",
    auth_headers={"Authorization": "Bearer s3cr3t-t0k3n"}
)

# 2. Initialize the manager
manager = McpManager([local_fs, clinical_db])

async def main():
    # 3. Connect to all servers
    await manager.connect_all()

    try:
        # 4. List aggregated tools (converted to OpenAI format)
        tools = await manager.get_openai_tools()
        print(f"Available tools: {[t['function']['name'] for t in tools]}")

        # 5. Call a tool
        # The manager handles routing and error mapping
        result = await manager.call_tool(
            tool_name="clinical_db_get_patient",
            arguments={"patient_id": "PT-12345"}
        )
        print("Result:", result.content[0].text)

    finally:
        # 6. Cleanup connections
        await manager.close()

if __name__ == "__main__":
    asyncio.run(main())
```

