@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
mdx 254 lines 7.82 KB
Raw
1 ---
2 title: "MCP"
3 description: "MCP (Model Control Protocol) class. Provides enhanced MCP server operations This matches the TypeScript ExperimentalMCP class functionality."
4 ---
5
6 <Callout type="warn" title="Deprecated">
7 Use a session's MCP endpoint instead: `composio.create(user_id, mcp=True)` returns a session that exposes `session.mcp.url` / `session.mcp.headers`. MCP is now opt-in per session; this standalone `composio.mcp` server-management API is kept only for backwards compatibility. Prefer the session MCP endpoint; do not generate new code against `composio.mcp`. See https://docs.composio.dev/docs/sessions-via-mcp
8 </Callout>
9
10 ## Methods
11
12 ### create()
13
14 Create a new MCP server configuration with specified toolkits and authentication settings.
15
16 ```python
17 def create(name: str, toolkits: List[Union[ConfigToolkit, str]], manually_manage_connections: bool = ..., allowed_tools: List[str] | None = ...) -> MCPCreateResponse
18 ```
19
20 **Parameters**
21
22 | Name | Type | Description |
23 |------|------|-------------|
24 | `name` | `str` | Unique name for the MCP configuration |
25 | `toolkits` | `List[Union[ConfigToolkit, str]]` | List of toolkit configurations. Can be either: - MCPToolkitConfig objects with detailed configuration - Strings representing toolkit names (for simple cases) |
26 | `manually_manage_connections?` | `bool` | Whether to manually manage account connections (default: False) |
27 | `allowed_tools?` | `List[str] \| None` | List of specific tools to enable across all toolkits (default: None for all tools) |
28
29 **Returns**
30
31 `MCPCreateResponse` — Created server details with generate method
32
33 **Example**
34
35 ```python
36 >>> # Using toolkit configuration objects with auth
37 >>> server = composio.experimental.mcp.create(
38 ... 'personal-mcp-server',
39 ... toolkits=[
40 ... {
41 ... 'toolkit': 'github',
42 ... 'auth_config_id': 'ac_xyz',
43 ... },
44 ... {
45 ... 'toolkit': 'slack',
46 ... 'auth_config_id': 'ac_abc',
47 ... },
48 ... ],
49 ... allowed_tools=['GITHUB_CREATE_AN_ISSUE', 'GITHUB_LIST_REPOS', 'SLACK_SEND_MESSAGE'],
50 ... manually_manage_connections=False
51 ... )
52 >>>
53 >>> # Using simple toolkit names (most common usage)
54 >>> server = composio.experimental.mcp.create(
55 ... 'simple-mcp-server',
56 ... toolkits=['composio_search', 'text_to_pdf'],
57 ... allowed_tools=['COMPOSIO_SEARCH_DUCK_DUCK_GO_SEARCH', 'TEXT_TO_PDF_CONVERT_TEXT_TO_PDF']
58 ... )
59 >>>
60 >>> # Using all tools from toolkits (default behavior)
61 >>> server = composio.experimental.mcp.create(
62 ... 'all-tools-server',
63 ... toolkits=['composio_search', 'text_to_pdf']
64 ... # allowed_tools=None means all tools from these toolkits
65 ... )
66 >>>
67 >>> # Get server instance for a user
68 >>> mcp = server.generate('user_12345')
69 ```
70
71 ---
72
73 ### list()
74
75 List MCP servers with optional filtering and pagination.
76
77 ```python
78 def list(page_no: int | None = ..., limit: int | None = ..., toolkits: str | None = ..., auth_config_ids: str | None = ..., name: str | None = ..., order_by: Literal['created_at', 'updated_at'] | None = ..., order_direction: Literal['asc', 'desc'] | None = ...) -> MCPListResponse
79 ```
80
81 **Parameters**
82
83 | Name | Type | Description |
84 |------|------|-------------|
85 | `page_no?` | `int \| None` | Page number for pagination (default: 1) |
86 | `limit?` | `int \| None` | Maximum items per page (default: 10) |
87 | `toolkits?` | `str \| None` | Filter by toolkit name (single string) |
88 | `auth_config_ids?` | `str \| None` | Filter by auth configuration ID (single string) |
89 | `name?` | `str \| None` | Filter by server name (partial match) |
90 | `order_by?` | `Literal['created_at', 'updated_at'] \| None` | Order by field ('created_at' or 'updated_at') |
91 | `order_direction?` | `Literal['asc', 'desc'] \| None` | Order direction ('asc' or 'desc') |
92
93 **Returns**
94
95 `MCPListResponse` — Paginated list of MCP servers
96
97 **Example**
98
99 ```python
100 >>> # List all servers
101 >>> all_servers = composio.experimental.mcp.list()
102 >>>
103 >>> # List with pagination
104 >>> paged_servers = composio.experimental.mcp.list(page_no=2, limit=5)
105 >>>
106 >>> # Filter by toolkit
107 >>> github_servers = composio.experimental.mcp.list(toolkits='github', name='personal')
108 ```
109
110 ---
111
112 ### get()
113
114 Retrieve detailed information about a specific MCP server/config.
115
116 ```python
117 def get(server_id: str)
118 ```
119
120 **Parameters**
121
122 | Name | Type | Description |
123 |------|------|-------------|
124 | `server_id` | `str` | The unique identifier of the MCP server/config |
125
126 **Example**
127
128 ```python
129 >>> server = composio.experimental.mcp.get('mcp_12345')
130 >>>
131 >>> print(server['name']) # "My Personal MCP Server"
132 >>> print(server['allowed_tools']) # ["GITHUB_CREATE_AN_ISSUE", "SLACK_SEND_MESSAGE"]
133 >>> print(server['toolkits']) # ["github", "slack"]
134 >>> print(server['server_instance_count']) # 3
135 ```
136
137 ---
138
139 ### update()
140
141 Update an existing MCP server configuration.
142
143 ```python
144 def update(server_id: str, name: str | None = ..., toolkits: List[Union[ConfigToolkit, str]] | None = ..., manually_manage_connections: bool | None = ..., allowed_tools: List[str] | None = ...)
145 ```
146
147 **Parameters**
148
149 | Name | Type | Description |
150 |------|------|-------------|
151 | `server_id` | `str` | The unique identifier of the MCP server to update |
152 | `name?` | `str \| None` | Optional new name for the MCP server |
153 | `toolkits?` | `List[Union[ConfigToolkit, str]] \| None` | Optional list of toolkit configurations (strings or objects) |
154 | `manually_manage_connections?` | `bool \| None` | Optional flag for connection management |
155 | `allowed_tools?` | `List[str] \| None` | Optional list of specific tools to enable across all toolkits |
156
157 **Example**
158
159 ```python
160 >>> # Update server name only
161 >>> updated_server = composio.experimental.mcp.update(
162 ... 'mcp_12345',
163 ... name='My Updated MCP Server'
164 ... )
165 >>>
166 >>> # Update toolkits and tools
167 >>> server_with_new_tools = composio.experimental.mcp.update(
168 ... 'mcp_12345',
169 ... toolkits=['github', 'slack'],
170 ... allowed_tools=['GITHUB_CREATE_AN_ISSUE', 'SLACK_SEND_MESSAGE']
171 ... )
172 >>>
173 >>> # Update with auth configs
174 >>> server_with_auth = composio.experimental.mcp.update(
175 ... 'mcp_12345',
176 ... toolkits=[
177 ... {'toolkit': 'github', 'auth_config_id': 'auth_abc123'},
178 ... {'toolkit': 'slack', 'auth_config_id': 'auth_def456'}
179 ... ],
180 ... allowed_tools=['GITHUB_CREATE_AN_ISSUE', 'SLACK_SEND_MESSAGE'],
181 ... manually_manage_connections=False
182 ... )
183 ```
184
185 ---
186
187 ### delete()
188
189 Permanently delete an MCP server configuration.
190
191 ```python
192 def delete(server_id: str) -> Dict[str, Any]
193 ```
194
195 **Parameters**
196
197 | Name | Type | Description |
198 |------|------|-------------|
199 | `server_id` | `str` | The unique identifier of the MCP server to delete |
200
201 **Returns**
202
203 `Dict[str, Any]` — Deletion result
204
205 **Example**
206
207 ```python
208 >>> # Delete a server
209 >>> result = composio.experimental.mcp.delete('mcp_12345')
210 >>>
211 >>> if result['deleted']:
212 ... print(f"Server {result['id']} has been successfully deleted")
213 >>> else:
214 ... print(f"Failed to delete server {result['id']}")
215 ```
216
217 ---
218
219 ### generate()
220
221 Get server URLs for an existing MCP server. This matches the TypeScript implementation exactly.
222
223 ```python
224 def generate(user_id: str, mcp_config_id: str, manually_manage_connections: bool | None = ...) -> MCPServerInstance
225 ```
226
227 **Parameters**
228
229 | Name | Type | Description |
230 |------|------|-------------|
231 | `user_id` | `str` | External user ID from your database |
232 | `mcp_config_id` | `str` | MCP configuration ID |
233 | `manually_manage_connections?` | `bool \| None` | Whether to manually manage connections (optional) |
234
235 **Returns**
236
237 `MCPServerInstance` — MCP server instance
238
239 **Example**
240
241 ```python
242 >>> mcp = composio.experimental.mcp.generate(
243 ... 'user_12345',
244 ... 'mcp_67890',
245 ... manually_manage_connections=False
246 ... )
247 >>>
248 >>> print(mcp['url']) # Server URL for the user
249 >>> print(mcp['allowed_tools']) # Available tools
250 ```
251
252 ---
253
254 [View source](https://github.com/composiohq/composio/blob/next/python/composio/core/models/mcp.py#L122)