@composio/claude-code-agents 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -0
- package/dist/index.cjs +124 -0
- package/dist/index.d.cts +112 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.js +103 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sampark Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# @composio/claude-code-agents
|
|
2
|
+
|
|
3
|
+
Composio provider for the [Claude Agent SDK](https://platform.claude.com/docs/en/agent-sdk/overview) (`@anthropic-ai/claude-agent-sdk`).
|
|
4
|
+
|
|
5
|
+
This provider enables seamless integration of Composio tools with Claude Code Agents, allowing you to use any Composio-supported tool (Gmail, Slack, GitHub, etc.) within your Claude agents.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @composio/claude-code-agents @composio/core @anthropic-ai/claude-agent-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Prerequisites
|
|
14
|
+
|
|
15
|
+
1. **Claude Code CLI**: The Claude Agent SDK requires Claude Code to be installed:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# macOS/Linux/WSL
|
|
19
|
+
curl -fsSL https://claude.ai/install.sh | bash
|
|
20
|
+
|
|
21
|
+
# or via Homebrew
|
|
22
|
+
brew install --cask claude-code
|
|
23
|
+
|
|
24
|
+
# or via npm
|
|
25
|
+
npm install -g @anthropic-ai/claude-code
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
2. **API Keys**:
|
|
29
|
+
- `ANTHROPIC_API_KEY`: Your Anthropic API key from [console.anthropic.com](https://console.anthropic.com)
|
|
30
|
+
- `COMPOSIO_API_KEY`: Your Composio API key from [app.composio.dev](https://app.composio.dev)
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { Composio } from '@composio/core';
|
|
36
|
+
import { ClaudeCodeAgentsProvider } from '@composio/claude-code-agents';
|
|
37
|
+
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
38
|
+
|
|
39
|
+
// Initialize Composio with the Claude Code Agents provider
|
|
40
|
+
const composio = new Composio({
|
|
41
|
+
apiKey: process.env.COMPOSIO_API_KEY,
|
|
42
|
+
provider: new ClaudeCodeAgentsProvider(),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
async function main() {
|
|
46
|
+
// Get Composio tools (e.g., Gmail tools)
|
|
47
|
+
const tools = await composio.tools.get('default', 'GMAIL_SEND_EMAIL');
|
|
48
|
+
|
|
49
|
+
// Create an MCP server configuration with the tools
|
|
50
|
+
const mcpServer = composio.provider.createMcpServer(tools, composio.tools.execute);
|
|
51
|
+
|
|
52
|
+
// Run a Claude agent with access to Composio tools
|
|
53
|
+
for await (const message of query({
|
|
54
|
+
prompt: 'Send an email to john@example.com saying hello',
|
|
55
|
+
options: {
|
|
56
|
+
mcpServers: { composio: mcpServer },
|
|
57
|
+
permissionMode: 'bypassPermissions',
|
|
58
|
+
allowDangerouslySkipPermissions: true,
|
|
59
|
+
},
|
|
60
|
+
})) {
|
|
61
|
+
if (message.type === 'assistant') {
|
|
62
|
+
console.log('Claude:', message.content);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
main();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API Reference
|
|
71
|
+
|
|
72
|
+
### `ClaudeCodeAgentsProvider`
|
|
73
|
+
|
|
74
|
+
The main provider class for integrating Composio tools with Claude Code Agents.
|
|
75
|
+
|
|
76
|
+
#### Constructor Options
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
interface ClaudeCodeAgentsProviderOptions {
|
|
80
|
+
serverName?: string; // Name for the MCP server (default: 'composio')
|
|
81
|
+
serverVersion?: string; // Version for the MCP server (default: '1.0.0')
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### Methods
|
|
86
|
+
|
|
87
|
+
##### `createMcpServer(tools, executeTool)`
|
|
88
|
+
|
|
89
|
+
Creates an MCP server configuration for use with Claude Agent SDK's `query()` function.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const mcpServer = provider.createMcpServer(tools, composio.tools.execute);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
##### `wrapTool(tool, executeTool)`
|
|
96
|
+
|
|
97
|
+
Wraps a single Composio tool as a Claude Agent SDK MCP tool.
|
|
98
|
+
|
|
99
|
+
##### `wrapTools(tools, executeTool)`
|
|
100
|
+
|
|
101
|
+
Wraps multiple Composio tools as Claude Agent SDK MCP tools.
|
|
102
|
+
|
|
103
|
+
## How It Works
|
|
104
|
+
|
|
105
|
+
The Claude Agent SDK uses MCP (Model Context Protocol) servers to provide tools to Claude agents. This provider:
|
|
106
|
+
|
|
107
|
+
1. Converts Composio tool definitions to MCP tool format
|
|
108
|
+
2. Creates an in-process MCP server using `createSdkMcpServer()`
|
|
109
|
+
3. Handles tool execution by routing calls through Composio's execution layer
|
|
110
|
+
|
|
111
|
+
## Examples
|
|
112
|
+
|
|
113
|
+
### Using Multiple Tools
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const tools = await composio.tools.get('default', [
|
|
117
|
+
'GMAIL_SEND_EMAIL',
|
|
118
|
+
'GMAIL_LIST_EMAILS',
|
|
119
|
+
'SLACK_POST_MESSAGE',
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
const mcpServer = composio.provider.createMcpServer(tools, composio.tools.execute);
|
|
123
|
+
|
|
124
|
+
for await (const message of query({
|
|
125
|
+
prompt: 'Check my latest emails and post a summary to #general on Slack',
|
|
126
|
+
options: {
|
|
127
|
+
mcpServers: { composio: mcpServer },
|
|
128
|
+
},
|
|
129
|
+
})) {
|
|
130
|
+
console.log(message);
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Custom Server Name
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
const provider = new ClaudeCodeAgentsProvider({
|
|
138
|
+
serverName: 'my-composio-tools',
|
|
139
|
+
serverVersion: '2.0.0',
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
ISC
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ClaudeCodeAgentsProvider: () => ClaudeCodeAgentsProvider
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_core = require("@composio/core");
|
|
27
|
+
var import_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
|
|
28
|
+
var import_json_schema_to_zod = require("@composio/json-schema-to-zod");
|
|
29
|
+
var ClaudeCodeAgentsProvider = class extends import_core.BaseAgenticProvider {
|
|
30
|
+
name = "claude-code-agents";
|
|
31
|
+
/**
|
|
32
|
+
* Wraps a Composio tool as a Claude Agent SDK MCP tool.
|
|
33
|
+
*
|
|
34
|
+
* @param composioTool - The Composio tool to wrap
|
|
35
|
+
* @param executeTool - Function to execute the tool
|
|
36
|
+
* @returns A Claude Agent SDK MCP tool definition
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const composioTool = {
|
|
41
|
+
* slug: 'GMAIL_SEND_EMAIL',
|
|
42
|
+
* description: 'Send an email via Gmail',
|
|
43
|
+
* inputParameters: {
|
|
44
|
+
* type: 'object',
|
|
45
|
+
* properties: {
|
|
46
|
+
* to: { type: 'string', description: 'Recipient email' },
|
|
47
|
+
* subject: { type: 'string', description: 'Email subject' },
|
|
48
|
+
* body: { type: 'string', description: 'Email body' },
|
|
49
|
+
* },
|
|
50
|
+
* required: ['to', 'subject', 'body'],
|
|
51
|
+
* },
|
|
52
|
+
* };
|
|
53
|
+
*
|
|
54
|
+
* const mcpTool = provider.wrapTool(composioTool, executeFn);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
wrapTool(composioTool, executeTool) {
|
|
58
|
+
const inputParams = composioTool.inputParameters ?? {};
|
|
59
|
+
const zodShape = (0, import_json_schema_to_zod.jsonSchemaToZodShape)(inputParams);
|
|
60
|
+
return (0, import_claude_agent_sdk.tool)(
|
|
61
|
+
composioTool.slug,
|
|
62
|
+
composioTool.description ?? `Execute ${composioTool.slug}`,
|
|
63
|
+
zodShape,
|
|
64
|
+
async (args) => {
|
|
65
|
+
try {
|
|
66
|
+
const result = await executeTool(composioTool.slug, args);
|
|
67
|
+
return {
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
text: typeof result === "string" ? result : JSON.stringify(result) ?? ""
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return {
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: "text",
|
|
80
|
+
text: JSON.stringify({
|
|
81
|
+
successful: false,
|
|
82
|
+
error: error instanceof Error ? error.message : String(error),
|
|
83
|
+
data: null
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Wraps multiple Composio tools as Claude Agent SDK MCP tools.
|
|
94
|
+
*
|
|
95
|
+
* @param tools - Array of Composio tools to wrap
|
|
96
|
+
* @param executeTool - Function to execute the tools
|
|
97
|
+
* @returns Array of Claude Agent SDK MCP tool definitions
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const tools = await composio.tools.get('default', ['GMAIL_SEND_EMAIL', 'SLACK_POST_MESSAGE']);
|
|
102
|
+
* const mcpTools = provider.wrapTools(tools, composio.tools.execute);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
wrapTools(tools, executeTool) {
|
|
106
|
+
return tools.map((tool) => this.wrapTool(tool, executeTool));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Transform MCP URL response into standard format.
|
|
110
|
+
*
|
|
111
|
+
* @param data - The MCP URL response data
|
|
112
|
+
* @returns Standard MCP server response format
|
|
113
|
+
*/
|
|
114
|
+
wrapMcpServerResponse(data) {
|
|
115
|
+
return data.map((item) => ({
|
|
116
|
+
url: new URL(item.url),
|
|
117
|
+
name: item.name
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
ClaudeCodeAgentsProvider
|
|
124
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BaseAgenticProvider, McpServerGetResponse, Tool, ExecuteToolFn, McpUrlResponse } from '@composio/core';
|
|
2
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
+
export { Options as ClaudeAgentOptions } from '@anthropic-ai/claude-agent-sdk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Claude Code Agents Provider
|
|
7
|
+
* To be used with the Claude Agent SDK (@anthropic-ai/claude-agent-sdk)
|
|
8
|
+
*
|
|
9
|
+
* This provider enables integration with Claude Code Agents SDK,
|
|
10
|
+
* allowing Composio tools to be used as MCP tools within Claude agents.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
* @module providers/claude-code-agents
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Type for a single Claude Agent SDK MCP tool definition
|
|
18
|
+
*/
|
|
19
|
+
type ClaudeAgentTool = ReturnType<typeof tool>;
|
|
20
|
+
/**
|
|
21
|
+
* Type for a collection of Claude Agent SDK MCP tools
|
|
22
|
+
*/
|
|
23
|
+
type ClaudeAgentToolCollection = ClaudeAgentTool[];
|
|
24
|
+
/**
|
|
25
|
+
* Provider for integrating Composio tools with Claude Code Agents SDK.
|
|
26
|
+
*
|
|
27
|
+
* This provider wraps Composio tools as MCP tools that can be used with
|
|
28
|
+
* the Claude Agent SDK's `query()` function via the `mcpServers` option.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { Composio } from '@composio/core';
|
|
33
|
+
* import { ClaudeCodeAgentsProvider } from '@composio/claude-code-agents';
|
|
34
|
+
* import { query, createSdkMcpServer } from '@anthropic-ai/claude-agent-sdk';
|
|
35
|
+
*
|
|
36
|
+
* const composio = new Composio({
|
|
37
|
+
* apiKey: process.env.COMPOSIO_API_KEY,
|
|
38
|
+
* provider: new ClaudeCodeAgentsProvider(),
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Get tools and create MCP server config using claude-agent-sdk's `createSdkMcpServer`
|
|
42
|
+
* const tools = await composio.tools.get('default', 'GMAIL_SEND_EMAIL');
|
|
43
|
+
* const mcpServer = createSdkMcpServer({
|
|
44
|
+
* name: 'composio',
|
|
45
|
+
* version: '1.0.0',
|
|
46
|
+
* tools,
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Use with Claude Agent SDK
|
|
50
|
+
* for await (const message of query({
|
|
51
|
+
* prompt: 'Send an email',
|
|
52
|
+
* options: {
|
|
53
|
+
* mcpServers: { composio: mcpServer },
|
|
54
|
+
* },
|
|
55
|
+
* })) {
|
|
56
|
+
* console.log(message);
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare class ClaudeCodeAgentsProvider extends BaseAgenticProvider<ClaudeAgentToolCollection, ClaudeAgentTool, McpServerGetResponse> {
|
|
61
|
+
readonly name = "claude-code-agents";
|
|
62
|
+
/**
|
|
63
|
+
* Wraps a Composio tool as a Claude Agent SDK MCP tool.
|
|
64
|
+
*
|
|
65
|
+
* @param composioTool - The Composio tool to wrap
|
|
66
|
+
* @param executeTool - Function to execute the tool
|
|
67
|
+
* @returns A Claude Agent SDK MCP tool definition
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const composioTool = {
|
|
72
|
+
* slug: 'GMAIL_SEND_EMAIL',
|
|
73
|
+
* description: 'Send an email via Gmail',
|
|
74
|
+
* inputParameters: {
|
|
75
|
+
* type: 'object',
|
|
76
|
+
* properties: {
|
|
77
|
+
* to: { type: 'string', description: 'Recipient email' },
|
|
78
|
+
* subject: { type: 'string', description: 'Email subject' },
|
|
79
|
+
* body: { type: 'string', description: 'Email body' },
|
|
80
|
+
* },
|
|
81
|
+
* required: ['to', 'subject', 'body'],
|
|
82
|
+
* },
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* const mcpTool = provider.wrapTool(composioTool, executeFn);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
wrapTool(composioTool: Tool, executeTool: ExecuteToolFn): ClaudeAgentTool;
|
|
89
|
+
/**
|
|
90
|
+
* Wraps multiple Composio tools as Claude Agent SDK MCP tools.
|
|
91
|
+
*
|
|
92
|
+
* @param tools - Array of Composio tools to wrap
|
|
93
|
+
* @param executeTool - Function to execute the tools
|
|
94
|
+
* @returns Array of Claude Agent SDK MCP tool definitions
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const tools = await composio.tools.get('default', ['GMAIL_SEND_EMAIL', 'SLACK_POST_MESSAGE']);
|
|
99
|
+
* const mcpTools = provider.wrapTools(tools, composio.tools.execute);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
wrapTools(tools: Tool[], executeTool: ExecuteToolFn): ClaudeAgentToolCollection;
|
|
103
|
+
/**
|
|
104
|
+
* Transform MCP URL response into standard format.
|
|
105
|
+
*
|
|
106
|
+
* @param data - The MCP URL response data
|
|
107
|
+
* @returns Standard MCP server response format
|
|
108
|
+
*/
|
|
109
|
+
wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { type ClaudeAgentTool, type ClaudeAgentToolCollection, ClaudeCodeAgentsProvider };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BaseAgenticProvider, McpServerGetResponse, Tool, ExecuteToolFn, McpUrlResponse } from '@composio/core';
|
|
2
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
+
export { Options as ClaudeAgentOptions } from '@anthropic-ai/claude-agent-sdk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Claude Code Agents Provider
|
|
7
|
+
* To be used with the Claude Agent SDK (@anthropic-ai/claude-agent-sdk)
|
|
8
|
+
*
|
|
9
|
+
* This provider enables integration with Claude Code Agents SDK,
|
|
10
|
+
* allowing Composio tools to be used as MCP tools within Claude agents.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
* @module providers/claude-code-agents
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Type for a single Claude Agent SDK MCP tool definition
|
|
18
|
+
*/
|
|
19
|
+
type ClaudeAgentTool = ReturnType<typeof tool>;
|
|
20
|
+
/**
|
|
21
|
+
* Type for a collection of Claude Agent SDK MCP tools
|
|
22
|
+
*/
|
|
23
|
+
type ClaudeAgentToolCollection = ClaudeAgentTool[];
|
|
24
|
+
/**
|
|
25
|
+
* Provider for integrating Composio tools with Claude Code Agents SDK.
|
|
26
|
+
*
|
|
27
|
+
* This provider wraps Composio tools as MCP tools that can be used with
|
|
28
|
+
* the Claude Agent SDK's `query()` function via the `mcpServers` option.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { Composio } from '@composio/core';
|
|
33
|
+
* import { ClaudeCodeAgentsProvider } from '@composio/claude-code-agents';
|
|
34
|
+
* import { query, createSdkMcpServer } from '@anthropic-ai/claude-agent-sdk';
|
|
35
|
+
*
|
|
36
|
+
* const composio = new Composio({
|
|
37
|
+
* apiKey: process.env.COMPOSIO_API_KEY,
|
|
38
|
+
* provider: new ClaudeCodeAgentsProvider(),
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Get tools and create MCP server config using claude-agent-sdk's `createSdkMcpServer`
|
|
42
|
+
* const tools = await composio.tools.get('default', 'GMAIL_SEND_EMAIL');
|
|
43
|
+
* const mcpServer = createSdkMcpServer({
|
|
44
|
+
* name: 'composio',
|
|
45
|
+
* version: '1.0.0',
|
|
46
|
+
* tools,
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Use with Claude Agent SDK
|
|
50
|
+
* for await (const message of query({
|
|
51
|
+
* prompt: 'Send an email',
|
|
52
|
+
* options: {
|
|
53
|
+
* mcpServers: { composio: mcpServer },
|
|
54
|
+
* },
|
|
55
|
+
* })) {
|
|
56
|
+
* console.log(message);
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare class ClaudeCodeAgentsProvider extends BaseAgenticProvider<ClaudeAgentToolCollection, ClaudeAgentTool, McpServerGetResponse> {
|
|
61
|
+
readonly name = "claude-code-agents";
|
|
62
|
+
/**
|
|
63
|
+
* Wraps a Composio tool as a Claude Agent SDK MCP tool.
|
|
64
|
+
*
|
|
65
|
+
* @param composioTool - The Composio tool to wrap
|
|
66
|
+
* @param executeTool - Function to execute the tool
|
|
67
|
+
* @returns A Claude Agent SDK MCP tool definition
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const composioTool = {
|
|
72
|
+
* slug: 'GMAIL_SEND_EMAIL',
|
|
73
|
+
* description: 'Send an email via Gmail',
|
|
74
|
+
* inputParameters: {
|
|
75
|
+
* type: 'object',
|
|
76
|
+
* properties: {
|
|
77
|
+
* to: { type: 'string', description: 'Recipient email' },
|
|
78
|
+
* subject: { type: 'string', description: 'Email subject' },
|
|
79
|
+
* body: { type: 'string', description: 'Email body' },
|
|
80
|
+
* },
|
|
81
|
+
* required: ['to', 'subject', 'body'],
|
|
82
|
+
* },
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* const mcpTool = provider.wrapTool(composioTool, executeFn);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
wrapTool(composioTool: Tool, executeTool: ExecuteToolFn): ClaudeAgentTool;
|
|
89
|
+
/**
|
|
90
|
+
* Wraps multiple Composio tools as Claude Agent SDK MCP tools.
|
|
91
|
+
*
|
|
92
|
+
* @param tools - Array of Composio tools to wrap
|
|
93
|
+
* @param executeTool - Function to execute the tools
|
|
94
|
+
* @returns Array of Claude Agent SDK MCP tool definitions
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const tools = await composio.tools.get('default', ['GMAIL_SEND_EMAIL', 'SLACK_POST_MESSAGE']);
|
|
99
|
+
* const mcpTools = provider.wrapTools(tools, composio.tools.execute);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
wrapTools(tools: Tool[], executeTool: ExecuteToolFn): ClaudeAgentToolCollection;
|
|
103
|
+
/**
|
|
104
|
+
* Transform MCP URL response into standard format.
|
|
105
|
+
*
|
|
106
|
+
* @param data - The MCP URL response data
|
|
107
|
+
* @returns Standard MCP server response format
|
|
108
|
+
*/
|
|
109
|
+
wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { type ClaudeAgentTool, type ClaudeAgentToolCollection, ClaudeCodeAgentsProvider };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
BaseAgenticProvider
|
|
4
|
+
} from "@composio/core";
|
|
5
|
+
import {
|
|
6
|
+
tool as sdkTool
|
|
7
|
+
} from "@anthropic-ai/claude-agent-sdk";
|
|
8
|
+
import { jsonSchemaToZodShape } from "@composio/json-schema-to-zod";
|
|
9
|
+
var ClaudeCodeAgentsProvider = class extends BaseAgenticProvider {
|
|
10
|
+
name = "claude-code-agents";
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Composio tool as a Claude Agent SDK MCP tool.
|
|
13
|
+
*
|
|
14
|
+
* @param composioTool - The Composio tool to wrap
|
|
15
|
+
* @param executeTool - Function to execute the tool
|
|
16
|
+
* @returns A Claude Agent SDK MCP tool definition
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const composioTool = {
|
|
21
|
+
* slug: 'GMAIL_SEND_EMAIL',
|
|
22
|
+
* description: 'Send an email via Gmail',
|
|
23
|
+
* inputParameters: {
|
|
24
|
+
* type: 'object',
|
|
25
|
+
* properties: {
|
|
26
|
+
* to: { type: 'string', description: 'Recipient email' },
|
|
27
|
+
* subject: { type: 'string', description: 'Email subject' },
|
|
28
|
+
* body: { type: 'string', description: 'Email body' },
|
|
29
|
+
* },
|
|
30
|
+
* required: ['to', 'subject', 'body'],
|
|
31
|
+
* },
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* const mcpTool = provider.wrapTool(composioTool, executeFn);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
wrapTool(composioTool, executeTool) {
|
|
38
|
+
const inputParams = composioTool.inputParameters ?? {};
|
|
39
|
+
const zodShape = jsonSchemaToZodShape(inputParams);
|
|
40
|
+
return sdkTool(
|
|
41
|
+
composioTool.slug,
|
|
42
|
+
composioTool.description ?? `Execute ${composioTool.slug}`,
|
|
43
|
+
zodShape,
|
|
44
|
+
async (args) => {
|
|
45
|
+
try {
|
|
46
|
+
const result = await executeTool(composioTool.slug, args);
|
|
47
|
+
return {
|
|
48
|
+
content: [
|
|
49
|
+
{
|
|
50
|
+
type: "text",
|
|
51
|
+
text: typeof result === "string" ? result : JSON.stringify(result) ?? ""
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: "text",
|
|
60
|
+
text: JSON.stringify({
|
|
61
|
+
successful: false,
|
|
62
|
+
error: error instanceof Error ? error.message : String(error),
|
|
63
|
+
data: null
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Wraps multiple Composio tools as Claude Agent SDK MCP tools.
|
|
74
|
+
*
|
|
75
|
+
* @param tools - Array of Composio tools to wrap
|
|
76
|
+
* @param executeTool - Function to execute the tools
|
|
77
|
+
* @returns Array of Claude Agent SDK MCP tool definitions
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const tools = await composio.tools.get('default', ['GMAIL_SEND_EMAIL', 'SLACK_POST_MESSAGE']);
|
|
82
|
+
* const mcpTools = provider.wrapTools(tools, composio.tools.execute);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
wrapTools(tools, executeTool) {
|
|
86
|
+
return tools.map((tool) => this.wrapTool(tool, executeTool));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Transform MCP URL response into standard format.
|
|
90
|
+
*
|
|
91
|
+
* @param data - The MCP URL response data
|
|
92
|
+
* @returns Standard MCP server response format
|
|
93
|
+
*/
|
|
94
|
+
wrapMcpServerResponse(data) {
|
|
95
|
+
return data.map((item) => ({
|
|
96
|
+
url: new URL(item.url),
|
|
97
|
+
name: item.name
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
export {
|
|
102
|
+
ClaudeCodeAgentsProvider
|
|
103
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@composio/claude-code-agents",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Composio provider for Claude Code Agents SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"README.md",
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"composio",
|
|
23
|
+
"claude",
|
|
24
|
+
"claude-code",
|
|
25
|
+
"agent-sdk",
|
|
26
|
+
"anthropic",
|
|
27
|
+
"mcp"
|
|
28
|
+
],
|
|
29
|
+
"author": "",
|
|
30
|
+
"license": "ISC",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"zod": "^3.25.76",
|
|
33
|
+
"@composio/json-schema-to-zod": "0.1.19"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@composio/core": "0.3.1",
|
|
37
|
+
"@anthropic-ai/claude-agent-sdk": ">=0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@anthropic-ai/claude-agent-sdk": "^0.1.9",
|
|
41
|
+
"tsup": "^8.5.0",
|
|
42
|
+
"typescript": "^5.9.2",
|
|
43
|
+
"vitest": "^3.2.4",
|
|
44
|
+
"zod": "^3.25.76",
|
|
45
|
+
"@composio/core": "0.3.1"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"clean": "git clean -xdf node_modules",
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"test": "vitest run"
|
|
51
|
+
},
|
|
52
|
+
"types": "dist/index.d.ts"
|
|
53
|
+
}
|