Skip to content
Zurück zur Startseite

§ INTEGRATION · MODEL CONTEXT PROTOCOL

MCP-Client-Wrapper

Ein einziger Aufruf umschließt eine MCP-ClientSession (Python) oder einen Client (JS). Jeder callTool läuft durch die Execlave-Tool-Allowlist-Enforcement, bevor der MCP-Server kontaktiert wird.

§ 01

Voraussetzungen

  • Execlave-Konto mit aktivem API-Schlüssel — Einstellungen → API-Schlüssel.
  • Ein registrierter Agent in Execlave. Verwenden Sie dessen kleingeschriebene Kebab-Case-agent_id.
  • MCP-SDK: Python mcp >=1.0 oder JS @modelcontextprotocol/sdk.
§ 02

Installation

Die Instrumentierung wird über ein optionales Extra (Python) und einen Subpath-Export (JS) bereitgestellt, sodass Standardinstallationen das MCP-SDK nicht mit installieren.

Python

pip install 'execlave-sdk[mcp]'

JavaScript / TypeScript

npm install @execlave/sdk @modelcontextprotocol/sdk
§ 03

Sofort einrichten mit einem Copilot

Fügen Sie diesen Prompt in Ihren KI-Coding-Assistenten ein.

§ Copy prompt · paste into your AI coding assistant
You are adding Execlave (an AI agent governance platform) to an existing project that uses the Model Context Protocol (MCP) SDK. Do not rewrite the MCP server or transport — only attach instrumentation to the CLIENT session. Rules you MUST follow:1. Install the correct extra. Python: `pip install 'execlave-sdk[mcp]'`. JS/TS: `npm install @execlave/sdk @modelcontextprotocol/sdk`.2. Read `EXECLAVE_API_KEY` from environment variables. Never hardcode keys. Add it to `.env.example`.3. Create exactly ONE Execlave client per process and reuse it.4. Wrap the MCP client/session IMMEDIATELY AFTER construction, BEFORE the first `call_tool` / `callTool` invocation. Python: `instrument_mcp_session(session, exe, agent_id="<stable-kebab-id>")`. JS: `instrumentMcpClient(mcp, exe, { agentId: '<stable-kebab-id>' })`.5. `agent_id` is a stable kebab-case string identifying this MCP-using agent in the Execlave dashboard.6. The wrap is IDEMPOTENT — a `_execlave_instrumented` marker is set so calling it twice is a no-op. Do not add your own check.7. Wrap the `call_tool` / `callTool` invocation in try/except for `execlave.errors.PolicyBlockedError` (Python) or `PolicyBlockedError` from `@execlave/sdk` (JS). On block, return a structured 4xx response containing `exc.violations`. Do NOT swallow.8. Do NOT call `exe.enforce_policy` manually before `call_tool` — the wrapper runs tool-allowlist enforcement on the tool name and arguments.9. Both `call_tool(name, args)` and `call_tool({name, arguments})` shapes are handled by the wrapper — do not normalise the call site yourself.10. On process shutdown, call `exe.flush()` (sync) or `await exe.shutdown()` (JS). Deliverables:- One diff per file. Touch only the MCP client construction site and the call site for tool execution.- Add `EXECLAVE_API_KEY` and optional `EXECLAVE_BASE_URL` to `.env.example`. Reference: https://www.execlave.com/docs/integrations/mcpAPI reference: https://www.execlave.com/docs/sdk-reference
§ 04

Schnellstart

Umschließen Sie den MCP-Client einmal; jeder Tool-Call wird governed.

Python

from mcp import ClientSessionfrom execlave import Execlavefrom execlave.integrations.mcp import instrument_mcp_session exe = Execlave(api_key="exe_prod_...") session = ClientSession(...)  # your normal MCP setupinstrument_mcp_session(session, exe, agent_id="ops-agent") # Every call_tool now enforces tool-allowlist policies BEFORE the# request reaches the MCP server. A PolicyBlockedError aborts the# call and never contacts the server.result = await session.call_tool("filesystem.read", {"path": "/etc/passwd"})

JavaScript / TypeScript

import { Client } from '@modelcontextprotocol/sdk/client/index.js';import { Execlave } from '@execlave/sdk';import { instrumentMcpClient } from '@execlave/sdk/integrations/mcp'; const exe = new Execlave({ apiKey: process.env.EXECLAVE_API_KEY! }); const mcp = new Client({ name: 'ops-app', version: '1.0' }, { capabilities: {} });instrumentMcpClient(mcp, exe, { agentId: 'ops-agent' }); const result = await mcp.callTool({  name: 'filesystem.read',  arguments: { path: '/etc/passwd' },});
§ 05

Umgang mit Blockierungen

Ein blockierter Tool-Call löst PolicyBlockedError aus, BEVOR die Anfrage den MCP-Server erreicht, sodass blockierte Aktionen keine Seiteneffekte verursachen können.

Python

from execlave.errors import PolicyBlockedError try:    result = await session.call_tool(name, arguments)except PolicyBlockedError as exc:    return {"error": "blocked", "violations": exc.violations}

JavaScript / TypeScript

import { PolicyBlockedError } from '@execlave/sdk'; try {  await mcp.callTool({ name, arguments: args });} catch (err) {  if (err instanceof PolicyBlockedError) {    return { error: 'blocked', violations: err.violations };  }  throw err;}
§ 06

Tool-Deskriptoren fixieren (Schutz vor Tool-Poisoning)

Eine Allowlist für Tool-Namen allein reicht nicht aus — MCP-Tool-Poisoning verändert die Beschreibung oder das Schema eines Tools, nachdem Sie ihm vertraut haben. Fixieren Sie den Deskriptor, damit eine Änderung sofort erkannt wird.

Mit aktivierter Tool Integrity fixieren Sie eine pro Agent geltende Baseline genehmigter (server, tool, descriptor hash)-Tupel. Jeder spätere Enforce-Aufruf vergleicht den aktuellen Deskriptor mit dieser Baseline und blockiert Abweichungen, nicht genehmigte Tools oder eine vergiftete Beschreibung, bevor der MCP-Server kontaktiert wird — mit manipulationssicheren Nachweisen, die auf die OWASP-Agentic-Posture abgebildet werden.
// Pin the approved MCP tool set once per deploy (after the wrap above).// Every later enforce call diffs the live descriptor against this baseline;// a drifted hash, an unapproved tool, or a poisoned description is blocked.const tools = (await mcp.listTools()).tools;await exe.reportToolBaseline({  agentId: 'ops-agent',  descriptors: tools.map((t) =>    exe.toolDescriptor({ server: 'github', tool: t.name, descriptor: t })),});
§ 07

Wie geht es weiter?

Model Context Protocol (MCP)-Integration — Execlave Docs