diff --git a/samples/BcMCPProxyPython/bc_mcp_proxy/proxy.py b/samples/BcMCPProxyPython/bc_mcp_proxy/proxy.py index 23c4aa50..b1dd2a0f 100644 --- a/samples/BcMCPProxyPython/bc_mcp_proxy/proxy.py +++ b/samples/BcMCPProxyPython/bc_mcp_proxy/proxy.py @@ -6,12 +6,18 @@ from urllib.parse import unquote import httpx +import mcp.types # module-level import so we can patch LATEST_PROTOCOL_VERSION in-place from mcp.client.session import ClientSession from mcp.client.streamable_http import streamablehttp_client from mcp.server import Server from mcp.server.stdio import stdio_server from mcp.types import Implementation +# Business Central's MCP server only accepts protocol version "2024-11-05". +# Newer versions of the MCP SDK default to a later protocol version which BC +# rejects with HTTP 400. We override the version before calling initialize(). +_BC_PROTOCOL_VERSION = "2024-11-05" + from .auth import TokenProvider, create_token_provider from .config import ProxyConfig @@ -56,7 +62,14 @@ async def run_proxy(config: ProxyConfig) -> None: remote_write, client_info=client_info, ) as remote_session: - init_result = await remote_session.initialize() + # Temporarily override the protocol version so BC accepts the + # initialize handshake (it only supports "2024-11-05"). + original_protocol_version = mcp.types.LATEST_PROTOCOL_VERSION + mcp.types.LATEST_PROTOCOL_VERSION = _BC_PROTOCOL_VERSION + try: + init_result = await remote_session.initialize() + finally: + mcp.types.LATEST_PROTOCOL_VERSION = original_protocol_version logger.debug("Connected to remote MCP server (protocol %s)", init_result.protocolVersion) instructions = config.instructions or ( diff --git a/samples/BcMCPProxyPython/pyproject.toml b/samples/BcMCPProxyPython/pyproject.toml index 17cd0b5e..eafe1a89 100644 --- a/samples/BcMCPProxyPython/pyproject.toml +++ b/samples/BcMCPProxyPython/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "bc-mcp-proxy" -version = "0.1.2" +version = "0.1.3" description = "Python-based MCP stdio proxy for Microsoft Dynamics 365 Business Central" readme = "README.md" requires-python = ">=3.10"