Metadata-Version: 2.4
Name: bc-mcp-proxy-daemon
Version: 0.2.0
Summary: MCP proxy for Microsoft Dynamics 365 Business Central with OAuth2 client credentials (daemon) authentication
Author: BlackCoronel
License-Expression: MIT
Project-URL: Homepage, https://github.com/BlackCoronel/bc-mcp-proxy-daemon
Project-URL: Repository, https://github.com/BlackCoronel/bc-mcp-proxy-daemon
Project-URL: Issues, https://github.com/BlackCoronel/bc-mcp-proxy-daemon/issues
Keywords: mcp,business-central,oauth2,proxy,dynamics-365
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: msal>=1.28.0
Requires-Dist: httpx>=0.27
Requires-Dist: mcp>=1.0
Dynamic: license-file

# bc-mcp-proxy-daemon

Proxy MCP (Model Context Protocol) para **Microsoft Dynamics 365 Business Central** con autenticación **OAuth2 Client Credentials** (service principal / daemon).

Actúa como puente entre clientes MCP stdio (como Claude Code) y el endpoint MCP de Business Central, gestionando automáticamente la obtención y renovación de tokens OAuth2 mediante MSAL.

## Requisitos

- Python >= 3.11
- Un App Registration en Azure AD con permisos para Business Central
- Credenciales: `tenant_id`, `client_id`, `client_secret`

## Instalación

```bash
pip install bc-mcp-proxy-daemon
```

Desde el código fuente:

```bash
git clone git@github.com:BlackCoronel/bc-mcp-proxy-daemon.git
cd bc-mcp-proxy-daemon
pip install -e .
```

## Configuración

Todos los parámetros se pueden configurar por **argumentos CLI** o **variables de entorno**. Los argumentos CLI tienen prioridad sobre las variables de entorno.

### Parámetros obligatorios

| CLI | Variable de entorno | Descripción |
|-----|---------------------|-------------|
| `--TenantId` | `BC_TENANT_ID` | Azure AD tenant ID |
| `--ClientId` | `BC_CLIENT_ID` | Application (client) ID del App Registration |
| `--ClientSecret` | `BC_CLIENT_SECRET` | Client secret del App Registration |

### Parámetros opcionales

| CLI | Variable de entorno | Default | Descripción |
|-----|---------------------|---------|-------------|
| `--Company` | `BC_COMPANY` | — | Nombre de la empresa en BC |
| `--Environment` | `BC_ENVIRONMENT` | `Production` | Entorno de BC (`Production`, `Sandbox`, etc.) |
| `--ConfigurationName` | `BC_CONFIGURATION_NAME` | — | Nombre de configuración MCP en BC |
| `--BaseUrl` | `BC_BASE_URL` | `https://api.businesscentral.dynamics.com` | URL base de la API |
| `--TokenScope` | `BC_TOKEN_SCOPE` | `https://api.businesscentral.dynamics.com/.default` | Scope OAuth2 |
| `--CustomAuthHeader` | `BC_CUSTOM_AUTH_HEADER` | — | Token bearer estático (omite OAuth2) |
| `--ServerName` | `BC_SERVER_NAME` | `BcMCPProxyPython` | Nombre del servidor MCP local |
| `--ServerVersion` | `BC_SERVER_VERSION` | `0.2.0` | Versión del servidor MCP local |
| `--Instructions` | `BC_INSTRUCTIONS` | — | Instrucciones personalizadas para el servidor MCP |
| `--HttpTimeoutSeconds` | `BC_HTTP_TIMEOUT_SECONDS` | `30` | Timeout para peticiones HTTP |
| `--SseTimeoutSeconds` | `BC_SSE_TIMEOUT_SECONDS` | `300` | Timeout para conexiones SSE |
| `--LogLevel` | `BC_LOG_LEVEL` | `INFO` | Nivel de log (`DEBUG`, `INFO`, `WARNING`, `ERROR`) |
| `--Debug` | `BC_DEBUG` | `false` | Activa logs de depuración |

## Uso

### Ejecución directa

```bash
python -m bc_mcp_proxy \
  --TenantId "tu-tenant-id" \
  --ClientId "tu-client-id" \
  --ClientSecret "tu-client-secret" \
  --Company "CRONUS España S.A." \
  --Environment Production
```

### Con variables de entorno

```bash
export BC_TENANT_ID="tu-tenant-id"
export BC_CLIENT_ID="tu-client-id"
export BC_CLIENT_SECRET="tu-client-secret"
export BC_COMPANY="CRONUS España S.A."
export BC_ENVIRONMENT="Production"

python -m bc_mcp_proxy
```

### Integración con Claude Code

Añade el proxy como servidor MCP en tu configuración de Claude Code (`.claude/settings.json` o similar):

```json
{
  "mcpServers": {
    "bc": {
      "command": "python",
      "args": [
        "-m", "bc_mcp_proxy",
        "--TenantId", "tu-tenant-id",
        "--ClientId", "tu-client-id",
        "--ClientSecret", "tu-client-secret",
        "--Company", "CRONUS España S.A.",
        "--Environment", "Production"
      ]
    }
  }
}
```

## Arquitectura

```
Claude Code (stdio) ←→ bc-mcp-proxy (stdio server) ←→ Business Central (Streamable HTTP)
                              │
                          MSAL OAuth2
                     (client credentials)
```

- **`proxy.py`** — Servidor MCP stdio que reenvía `list_tools` y `call_tool` al endpoint remoto de BC
- **`auth.py`** — Proveedores de tokens: `MsalClientCredentialsTokenProvider` (OAuth2) o `StaticTokenProvider` (bearer fijo)
- **`config.py`** — Dataclass con toda la configuración del proxy
- **`__main__.py`** — CLI parser y entry point

## Dependencias

- [`mcp`](https://pypi.org/project/mcp/) >= 1.0 — SDK del Model Context Protocol
- [`msal`](https://pypi.org/project/msal/) >= 1.28.0 — Microsoft Authentication Library
- [`httpx`](https://pypi.org/project/httpx/) >= 0.27 — Cliente HTTP async

## Licencia

MIT
