Files
Alberto Schiabel 8086ef02cb fix(examples): align Python and TypeScript examples with current backend (#4107)
## Summary

- Repairs runnable TypeScript and Python examples for current backend
requirements, including authenticated MCP endpoints, current transports,
valid tool identifiers, provider limits, and resource uniqueness.
- Replaces placeholder resource IDs with explicit `COMPOSIO_EXAMPLES_*`
configuration and makes failed examples exit loudly.
- Adds `scripts/examples-provision.mjs` as an idempotent provisioning
check for a disposable examples project.

## Scope

- This PR no longer changes the Python SDK runtime or generated-client
dependency.
- Python remains pinned to the published `composio-client==1.43.0` in
`pyproject.toml`, `setup.py`, and `uv.lock`.
- The owned 2.x client integration is deferred until that client
completes its release guarantees and is explicitly published.
- The scheduled live workflow and manifest remain deferred until their
runner is tracked.

## Verification

- `make chk`
- `make tst` (`927 passed, 33 skipped`)
- Hosted checks rerun against commit `12691aca7`.
2026-08-11 19:45:58 +02:00

48 lines
1.6 KiB
Python

import asyncio
import os
import time
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from composio import Composio
composio = Composio()
# Slack auth config and user id (raise KeyError when unset)
slack_auth_config_id = os.environ["COMPOSIO_EXAMPLES_SLACK_AUTH_CONFIG_ID"]
user_id = os.environ["COMPOSIO_EXAMPLES_USER_ID"]
mcp_config = composio.mcp.create(
# Named `examples-<label>-<unix-seconds>` so the provisioning script's --gc
# can tell this throwaway config from one created by hand. The API caps
# this name at 30 characters, so the label stays short.
name=f"examples-lc-slack-{int(time.time())}",
toolkits=[{"toolkit": "slack", "auth_config_id": slack_auth_config_id}],
# Keep the exposed tool list small; LLM providers cap tools per request
allowed_tools=["SLACK_LIST_ALL_CHANNELS", "SLACK_SEARCH_MESSAGES"],
)
mcp_server = mcp_config.generate(user_id=user_id) # type: ignore[call-arg] # generate is typed as a bare Callable; runtime accepts the user_id keyword
client = MultiServerMCPClient(
{
"composio": {
"url": mcp_server["url"],
"transport": "streamable_http",
# The MCP endpoint authenticates with your Composio API key
"headers": {"x-api-key": os.environ["COMPOSIO_API_KEY"]},
}
}
)
async def langchain_mcp(message: str):
tools = await client.get_tools()
agent = create_react_agent("openai:gpt-4.1", tools)
response = await agent.ainvoke({"messages": message})
return response
mcp_response = asyncio.run(langchain_mcp("Show me 20 most used slack channels"))