@autonomys/auto-mcp-servers 0.1.2 → 1.4.20
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 +18 -0
- package/README.md +101 -101
- package/dist/auto-drive/index.js +4 -4
- package/dist/bin/main.js +11 -11
- package/package.json +43 -42
- package/src/auto-drive/handlers.ts +110 -110
- package/src/auto-drive/index.ts +57 -57
- package/src/bin/auto-drive.ts +14 -14
- package/src/bin/main.ts +45 -45
- package/src/index.ts +2 -2
- package/tsconfig.json +10 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Autonomys Network (autonomys.xyz)
|
|
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
|
+
1. **Attribution**: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
2. **No Warranty**: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
15
|
+
|
|
16
|
+
3. **Limitation of Liability**: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
+
|
|
18
|
+
---
|
package/README.md
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
# Autonomys MCP Servers
|
|
2
|
-
|
|
3
|
-
This package provides Model Context Protocol (MCP) servers for Autonomys services. These servers expose Autonomys SDK functionality as MCP tools that can be used with Claude Desktop and other MCP clients, or integrated into agent frameworks.
|
|
4
|
-
|
|
5
|
-
## Available Servers
|
|
6
|
-
|
|
7
|
-
### Auto Drive Server
|
|
8
|
-
|
|
9
|
-
The Auto Drive server exposes functionality from the `@autonomys/auto-drive` package as MCP tools.
|
|
10
|
-
|
|
11
|
-
#### Tools
|
|
12
|
-
|
|
13
|
-
The Auto Drive server provides the following tools:
|
|
14
|
-
|
|
15
|
-
- `upload-object`: Upload an object (as JSON data) to the Autonomys network.
|
|
16
|
-
- `download-object`: Download a text-based object (`text/*` or `application/json`) from the Autonomys network using its CID.
|
|
17
|
-
- `search-objects`: Search for objects on the Autonomys network by name or CID fragment. Returns a JSON object containing an array of results, each including the object's name, CID, type, size, and mimeType (for files).
|
|
18
|
-
|
|
19
|
-
More servers and tools will be coming soon!
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
### With Claude Desktop
|
|
24
|
-
|
|
25
|
-
1. Install Claude Desktop
|
|
26
|
-
2. Edit your `claude_desktop_config.json` file:
|
|
27
|
-
|
|
28
|
-
```json
|
|
29
|
-
{
|
|
30
|
-
"mcpServers": {
|
|
31
|
-
"auto-drive": {
|
|
32
|
-
"command": "npx",
|
|
33
|
-
"args": ["-y", "@autonomys/auto-mcp-servers", "auto-drive"],
|
|
34
|
-
"env": {
|
|
35
|
-
"AUTO_DRIVE_API_KEY": "your-api-key",
|
|
36
|
-
"ENCRYPTION_PASSWORD": "my-password (optional)",
|
|
37
|
-
"NETWORK": "mainnet or taurus (optional, defaults to mainnet)"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
4. Restart Claude Desktop
|
|
45
|
-
|
|
46
|
-
### In Agent Frameworks
|
|
47
|
-
|
|
48
|
-
You can use these MCP servers as tools with agent frameworks such as LangChain.
|
|
49
|
-
|
|
50
|
-
1. Install the Auto Drive server into your project:
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
npm install @autonomys/auto-mcp-servers
|
|
54
|
-
# or
|
|
55
|
-
yarn add @autonomys/auto-mcp-servers
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
2. Use the Auto Drive server as a tool in your agent project:
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
|
62
|
-
import {
|
|
63
|
-
StdioClientTransport,
|
|
64
|
-
StdioServerParameters,
|
|
65
|
-
} from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
66
|
-
import { loadMcpTools } from '@langchain/mcp-adapters'
|
|
67
|
-
import { StructuredToolInterface } from '@langchain/core/tools'
|
|
68
|
-
import { ChatOpenAI } from '@langchain/openai'
|
|
69
|
-
|
|
70
|
-
// Create Auto Drive tools with a single function
|
|
71
|
-
const createAutoDriveTools = async (apiKey: string): Promise<StructuredToolInterface[]> => {
|
|
72
|
-
// Set up transport for Auto Drive server
|
|
73
|
-
const transport = new StdioClientTransport({
|
|
74
|
-
command: process.execPath,
|
|
75
|
-
args: ['node_modules/.bin/auto-drive-server'],
|
|
76
|
-
env: { AUTO_DRIVE_API_KEY: apiKey },
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
// Initialize client and connect
|
|
80
|
-
const client = new Client({ name: 'auto-drive', version: '0.0.1' })
|
|
81
|
-
client.connect(transport)
|
|
82
|
-
|
|
83
|
-
// Load MCP tools
|
|
84
|
-
return await loadMcpTools('auto-drive', client)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Create tools with your API key
|
|
88
|
-
const tools = await createAutoDriveTools('your-api-key')
|
|
89
|
-
|
|
90
|
-
// Initialize the ChatOpenAI model
|
|
91
|
-
const model = new ChatOpenAI({ modelName: 'gpt-4o' })
|
|
92
|
-
|
|
93
|
-
const result = await model
|
|
94
|
-
.bindTools(tools)
|
|
95
|
-
.invoke('Upload a profound thought to the Autonomys network')
|
|
96
|
-
console.log(result)
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## License
|
|
100
|
-
|
|
101
|
-
MIT
|
|
1
|
+
# Autonomys MCP Servers
|
|
2
|
+
|
|
3
|
+
This package provides Model Context Protocol (MCP) servers for Autonomys services. These servers expose Autonomys SDK functionality as MCP tools that can be used with Claude Desktop and other MCP clients, or integrated into agent frameworks.
|
|
4
|
+
|
|
5
|
+
## Available Servers
|
|
6
|
+
|
|
7
|
+
### Auto Drive Server
|
|
8
|
+
|
|
9
|
+
The Auto Drive server exposes functionality from the `@autonomys/auto-drive` package as MCP tools.
|
|
10
|
+
|
|
11
|
+
#### Tools
|
|
12
|
+
|
|
13
|
+
The Auto Drive server provides the following tools:
|
|
14
|
+
|
|
15
|
+
- `upload-object`: Upload an object (as JSON data) to the Autonomys network.
|
|
16
|
+
- `download-object`: Download a text-based object (`text/*` or `application/json`) from the Autonomys network using its CID.
|
|
17
|
+
- `search-objects`: Search for objects on the Autonomys network by name or CID fragment. Returns a JSON object containing an array of results, each including the object's name, CID, type, size, and mimeType (for files).
|
|
18
|
+
|
|
19
|
+
More servers and tools will be coming soon!
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### With Claude Desktop
|
|
24
|
+
|
|
25
|
+
1. Install Claude Desktop
|
|
26
|
+
2. Edit your `claude_desktop_config.json` file:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"auto-drive": {
|
|
32
|
+
"command": "npx",
|
|
33
|
+
"args": ["-y", "@autonomys/auto-mcp-servers", "auto-drive"],
|
|
34
|
+
"env": {
|
|
35
|
+
"AUTO_DRIVE_API_KEY": "your-api-key",
|
|
36
|
+
"ENCRYPTION_PASSWORD": "my-password (optional)",
|
|
37
|
+
"NETWORK": "mainnet or taurus (optional, defaults to mainnet)"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
4. Restart Claude Desktop
|
|
45
|
+
|
|
46
|
+
### In Agent Frameworks
|
|
47
|
+
|
|
48
|
+
You can use these MCP servers as tools with agent frameworks such as LangChain.
|
|
49
|
+
|
|
50
|
+
1. Install the Auto Drive server into your project:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install @autonomys/auto-mcp-servers
|
|
54
|
+
# or
|
|
55
|
+
yarn add @autonomys/auto-mcp-servers
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
2. Use the Auto Drive server as a tool in your agent project:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
|
62
|
+
import {
|
|
63
|
+
StdioClientTransport,
|
|
64
|
+
StdioServerParameters,
|
|
65
|
+
} from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
66
|
+
import { loadMcpTools } from '@langchain/mcp-adapters'
|
|
67
|
+
import { StructuredToolInterface } from '@langchain/core/tools'
|
|
68
|
+
import { ChatOpenAI } from '@langchain/openai'
|
|
69
|
+
|
|
70
|
+
// Create Auto Drive tools with a single function
|
|
71
|
+
const createAutoDriveTools = async (apiKey: string): Promise<StructuredToolInterface[]> => {
|
|
72
|
+
// Set up transport for Auto Drive server
|
|
73
|
+
const transport = new StdioClientTransport({
|
|
74
|
+
command: process.execPath,
|
|
75
|
+
args: ['node_modules/.bin/auto-drive-server'],
|
|
76
|
+
env: { AUTO_DRIVE_API_KEY: apiKey },
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// Initialize client and connect
|
|
80
|
+
const client = new Client({ name: 'auto-drive', version: '0.0.1' })
|
|
81
|
+
client.connect(transport)
|
|
82
|
+
|
|
83
|
+
// Load MCP tools
|
|
84
|
+
return await loadMcpTools('auto-drive', client)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Create tools with your API key
|
|
88
|
+
const tools = await createAutoDriveTools('your-api-key')
|
|
89
|
+
|
|
90
|
+
// Initialize the ChatOpenAI model
|
|
91
|
+
const model = new ChatOpenAI({ modelName: 'gpt-4o' })
|
|
92
|
+
|
|
93
|
+
const result = await model
|
|
94
|
+
.bindTools(tools)
|
|
95
|
+
.invoke('Upload a profound thought to the Autonomys network')
|
|
96
|
+
console.log(result)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|
package/dist/auto-drive/index.js
CHANGED
|
@@ -20,10 +20,10 @@ const { uploadObjectHandler, downloadObjectHandler, searchObjectsHandler } = cre
|
|
|
20
20
|
export const autoDriveServer = new McpServer({ name: 'Auto Drive', version: '0.1.2' });
|
|
21
21
|
autoDriveServer.tool('upload-object', 'Upload an object permanently to the Autonomys Network using Auto Drive, any objects uploaded here will be permanently available onchain. This is useful for storing data that you want to keep forever.', {
|
|
22
22
|
filename: z.string().describe('The filename to save the object as.'),
|
|
23
|
-
data: z.record(z.string(), z.any()).describe(`
|
|
24
|
-
Data you want to permanently store onchain saved as a JSON object with any key-value pairs.
|
|
25
|
-
The keys are strings that describe the type of data being stored.
|
|
26
|
-
The values are the actual data being stored.
|
|
23
|
+
data: z.record(z.string(), z.any()).describe(`
|
|
24
|
+
Data you want to permanently store onchain saved as a JSON object with any key-value pairs.
|
|
25
|
+
The keys are strings that describe the type of data being stored.
|
|
26
|
+
The values are the actual data being stored.
|
|
27
27
|
`),
|
|
28
28
|
}, (_a, _extra_1) => __awaiter(void 0, [_a, _extra_1], void 0, function* ({ filename, data }, _extra) {
|
|
29
29
|
return yield uploadObjectHandler({ filename, data });
|
package/dist/bin/main.js
CHANGED
|
@@ -11,17 +11,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
12
12
|
import { autoDriveServer } from '../auto-drive/index.js';
|
|
13
13
|
const showHelp = () => {
|
|
14
|
-
console.log(`
|
|
15
|
-
Usage: auto-mcp-servers [server-name]
|
|
16
|
-
|
|
17
|
-
Available servers:
|
|
18
|
-
auto-drive Start the Auto Drive MCP server
|
|
19
|
-
|
|
20
|
-
Environment variables:
|
|
21
|
-
For Auto Drive server:
|
|
22
|
-
AUTO_DRIVE_API_KEY API key for Auto Drive (required)
|
|
23
|
-
NETWORK 'mainnet' (default) or 'taurus'
|
|
24
|
-
ENCRYPTION_PASSWORD Password for encryption (optional)
|
|
14
|
+
console.log(`
|
|
15
|
+
Usage: auto-mcp-servers [server-name]
|
|
16
|
+
|
|
17
|
+
Available servers:
|
|
18
|
+
auto-drive Start the Auto Drive MCP server
|
|
19
|
+
|
|
20
|
+
Environment variables:
|
|
21
|
+
For Auto Drive server:
|
|
22
|
+
AUTO_DRIVE_API_KEY API key for Auto Drive (required)
|
|
23
|
+
NETWORK 'mainnet' (default) or 'taurus'
|
|
24
|
+
ENCRYPTION_PASSWORD Password for encryption (optional)
|
|
25
25
|
`);
|
|
26
26
|
process.exit(1);
|
|
27
27
|
};
|
package/package.json
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@autonomys/auto-mcp-servers",
|
|
3
|
-
"packageManager": "yarn@4.7.0",
|
|
4
|
-
"version": "
|
|
5
|
-
"description": "Autonomys Network MCP servers",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/autonomys/auto-sdk"
|
|
9
|
-
},
|
|
10
|
-
"author": {
|
|
11
|
-
"name": "Autonomys",
|
|
12
|
-
"url": "https://www.autonomys.xyz"
|
|
13
|
-
},
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/autonomys/auto-sdk/issues"
|
|
16
|
-
},
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"type": "module",
|
|
19
|
-
"main": "dist/index.js",
|
|
20
|
-
"bin": {
|
|
21
|
-
"auto-drive-server": "./dist/bin/auto-drive.js",
|
|
22
|
-
"auto-mcp-servers": "./dist/bin/main.js"
|
|
23
|
-
},
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "tsc",
|
|
26
|
-
"prepublishOnly": "npm run build"
|
|
27
|
-
},
|
|
28
|
-
"keywords": [
|
|
29
|
-
"mcp",
|
|
30
|
-
"server"
|
|
31
|
-
],
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"@autonomys/auto-drive": "^1.4.
|
|
34
|
-
"@modelcontextprotocol/sdk": "^1.9.0",
|
|
35
|
-
"zod": "^3.24.2"
|
|
36
|
-
},
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"@types/node": "22.14.0",
|
|
39
|
-
"ts-node": "^10.9.1",
|
|
40
|
-
"typescript": "^5.
|
|
41
|
-
}
|
|
42
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@autonomys/auto-mcp-servers",
|
|
3
|
+
"packageManager": "yarn@4.7.0",
|
|
4
|
+
"version": "1.4.20",
|
|
5
|
+
"description": "Autonomys Network MCP servers",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/autonomys/auto-sdk"
|
|
9
|
+
},
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Autonomys",
|
|
12
|
+
"url": "https://www.autonomys.xyz"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/autonomys/auto-sdk/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"bin": {
|
|
21
|
+
"auto-drive-server": "./dist/bin/auto-drive.js",
|
|
22
|
+
"auto-mcp-servers": "./dist/bin/main.js"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"mcp",
|
|
30
|
+
"server"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@autonomys/auto-drive": "^1.4.20",
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.9.0",
|
|
35
|
+
"zod": "^3.24.2"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "22.14.0",
|
|
39
|
+
"ts-node": "^10.9.1",
|
|
40
|
+
"typescript": "^5.8.3"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "838c478688bcdf9a757cc9e4a4b2e5ff36b15e64"
|
|
43
|
+
}
|
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import { createAutoDriveApi, UploadFileOptions } from '@autonomys/auto-drive'
|
|
2
|
-
|
|
3
|
-
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'
|
|
4
|
-
|
|
5
|
-
export const createAutoDriveHandlers = (
|
|
6
|
-
apiKey: string,
|
|
7
|
-
network: 'taurus' | 'mainnet',
|
|
8
|
-
encryptionPassword?: string,
|
|
9
|
-
) => {
|
|
10
|
-
const autoDriveApi = createAutoDriveApi({ apiKey, network })
|
|
11
|
-
const uploadOptions: UploadFileOptions | undefined = encryptionPassword
|
|
12
|
-
? { password: encryptionPassword }
|
|
13
|
-
: undefined
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
uploadObjectHandler: async ({
|
|
17
|
-
filename,
|
|
18
|
-
data,
|
|
19
|
-
}: {
|
|
20
|
-
filename: string
|
|
21
|
-
data: Record<string, any>
|
|
22
|
-
}): Promise<CallToolResult> => {
|
|
23
|
-
const cid = await autoDriveApi.uploadObjectAsJSON({ data }, filename, uploadOptions)
|
|
24
|
-
return { content: [{ type: 'text', text: `Object uploaded successfully with ${cid}` }] }
|
|
25
|
-
},
|
|
26
|
-
downloadObjectHandler: async ({ cid }: { cid: string }): Promise<CallToolResult> => {
|
|
27
|
-
try {
|
|
28
|
-
// Get object summary to determine type and metadata
|
|
29
|
-
const summaries = await autoDriveApi.searchByNameOrCID(cid)
|
|
30
|
-
if (!summaries || summaries.length === 0) {
|
|
31
|
-
throw new Error(`Object not found for CID: ${cid}`)
|
|
32
|
-
}
|
|
33
|
-
const summary = summaries[0]
|
|
34
|
-
|
|
35
|
-
// Handle folders
|
|
36
|
-
if (summary.type === 'folder') {
|
|
37
|
-
return {
|
|
38
|
-
isError: true,
|
|
39
|
-
content: [
|
|
40
|
-
{
|
|
41
|
-
type: 'text',
|
|
42
|
-
text: `Error: CID ${cid} points to a folder, which cannot be downloaded directly with this tool.`,
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const mimeType = summary.mimeType || 'application/octet-stream'
|
|
49
|
-
const filename = summary.name || `download-${cid}`
|
|
50
|
-
|
|
51
|
-
// Handle only text-based types
|
|
52
|
-
if (mimeType.startsWith('text/') || mimeType === 'application/json') {
|
|
53
|
-
const stream = await autoDriveApi.downloadFile(cid, encryptionPassword)
|
|
54
|
-
let fileBuffer = Buffer.alloc(0)
|
|
55
|
-
for await (const chunk of stream) {
|
|
56
|
-
fileBuffer = Buffer.concat([fileBuffer, chunk])
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const text = fileBuffer.toString('utf-8')
|
|
60
|
-
return {
|
|
61
|
-
content: [{ type: 'text', text }],
|
|
62
|
-
}
|
|
63
|
-
} catch (e) {
|
|
64
|
-
console.error(`Failed to decode text content for ${filename} (${mimeType})`, e)
|
|
65
|
-
return {
|
|
66
|
-
isError: true,
|
|
67
|
-
content: [
|
|
68
|
-
{
|
|
69
|
-
type: 'text',
|
|
70
|
-
text: `Error: Failed to decode file content for ${filename} as UTF-8 text.`,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// For all other types, return an error
|
|
78
|
-
return {
|
|
79
|
-
isError: true,
|
|
80
|
-
content: [
|
|
81
|
-
{
|
|
82
|
-
type: 'text',
|
|
83
|
-
text: `Error: File type \'${mimeType}\' is not supported for direct download in this client. Only text/* and application/json are supported.`,
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
}
|
|
87
|
-
} catch (error: any) {
|
|
88
|
-
console.error(`Failed to download object with CID ${cid}:`, error)
|
|
89
|
-
const errorMessage = error.message || 'Unknown error occurred during download.'
|
|
90
|
-
return {
|
|
91
|
-
isError: true,
|
|
92
|
-
content: [{ type: 'text', text: `Error downloading object: ${errorMessage}` }],
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
searchObjectsHandler: async ({ query }: { query: string }): Promise<CallToolResult> => {
|
|
97
|
-
const summaries = await autoDriveApi.searchByNameOrCID(query)
|
|
98
|
-
const results = summaries.map((s) => ({
|
|
99
|
-
name: s.name,
|
|
100
|
-
cid: s.headCid,
|
|
101
|
-
type: s.type,
|
|
102
|
-
size: s.size,
|
|
103
|
-
...(s.type === 'file' && { mimeType: s.mimeType }),
|
|
104
|
-
}))
|
|
105
|
-
return {
|
|
106
|
-
content: [{ type: 'text', text: JSON.stringify({ results }, null, 2) }],
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
}
|
|
110
|
-
}
|
|
1
|
+
import { createAutoDriveApi, UploadFileOptions } from '@autonomys/auto-drive'
|
|
2
|
+
|
|
3
|
+
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'
|
|
4
|
+
|
|
5
|
+
export const createAutoDriveHandlers = (
|
|
6
|
+
apiKey: string,
|
|
7
|
+
network: 'taurus' | 'mainnet',
|
|
8
|
+
encryptionPassword?: string,
|
|
9
|
+
) => {
|
|
10
|
+
const autoDriveApi = createAutoDriveApi({ apiKey, network })
|
|
11
|
+
const uploadOptions: UploadFileOptions | undefined = encryptionPassword
|
|
12
|
+
? { password: encryptionPassword }
|
|
13
|
+
: undefined
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
uploadObjectHandler: async ({
|
|
17
|
+
filename,
|
|
18
|
+
data,
|
|
19
|
+
}: {
|
|
20
|
+
filename: string
|
|
21
|
+
data: Record<string, any>
|
|
22
|
+
}): Promise<CallToolResult> => {
|
|
23
|
+
const cid = await autoDriveApi.uploadObjectAsJSON({ data }, filename, uploadOptions)
|
|
24
|
+
return { content: [{ type: 'text', text: `Object uploaded successfully with ${cid}` }] }
|
|
25
|
+
},
|
|
26
|
+
downloadObjectHandler: async ({ cid }: { cid: string }): Promise<CallToolResult> => {
|
|
27
|
+
try {
|
|
28
|
+
// Get object summary to determine type and metadata
|
|
29
|
+
const summaries = await autoDriveApi.searchByNameOrCID(cid)
|
|
30
|
+
if (!summaries || summaries.length === 0) {
|
|
31
|
+
throw new Error(`Object not found for CID: ${cid}`)
|
|
32
|
+
}
|
|
33
|
+
const summary = summaries[0]
|
|
34
|
+
|
|
35
|
+
// Handle folders
|
|
36
|
+
if (summary.type === 'folder') {
|
|
37
|
+
return {
|
|
38
|
+
isError: true,
|
|
39
|
+
content: [
|
|
40
|
+
{
|
|
41
|
+
type: 'text',
|
|
42
|
+
text: `Error: CID ${cid} points to a folder, which cannot be downloaded directly with this tool.`,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const mimeType = summary.mimeType || 'application/octet-stream'
|
|
49
|
+
const filename = summary.name || `download-${cid}`
|
|
50
|
+
|
|
51
|
+
// Handle only text-based types
|
|
52
|
+
if (mimeType.startsWith('text/') || mimeType === 'application/json') {
|
|
53
|
+
const stream = await autoDriveApi.downloadFile(cid, encryptionPassword)
|
|
54
|
+
let fileBuffer = Buffer.alloc(0)
|
|
55
|
+
for await (const chunk of stream) {
|
|
56
|
+
fileBuffer = Buffer.concat([fileBuffer, chunk])
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const text = fileBuffer.toString('utf-8')
|
|
60
|
+
return {
|
|
61
|
+
content: [{ type: 'text', text }],
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error(`Failed to decode text content for ${filename} (${mimeType})`, e)
|
|
65
|
+
return {
|
|
66
|
+
isError: true,
|
|
67
|
+
content: [
|
|
68
|
+
{
|
|
69
|
+
type: 'text',
|
|
70
|
+
text: `Error: Failed to decode file content for ${filename} as UTF-8 text.`,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// For all other types, return an error
|
|
78
|
+
return {
|
|
79
|
+
isError: true,
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
type: 'text',
|
|
83
|
+
text: `Error: File type \'${mimeType}\' is not supported for direct download in this client. Only text/* and application/json are supported.`,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
}
|
|
87
|
+
} catch (error: any) {
|
|
88
|
+
console.error(`Failed to download object with CID ${cid}:`, error)
|
|
89
|
+
const errorMessage = error.message || 'Unknown error occurred during download.'
|
|
90
|
+
return {
|
|
91
|
+
isError: true,
|
|
92
|
+
content: [{ type: 'text', text: `Error downloading object: ${errorMessage}` }],
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
searchObjectsHandler: async ({ query }: { query: string }): Promise<CallToolResult> => {
|
|
97
|
+
const summaries = await autoDriveApi.searchByNameOrCID(query)
|
|
98
|
+
const results = summaries.map((s) => ({
|
|
99
|
+
name: s.name,
|
|
100
|
+
cid: s.headCid,
|
|
101
|
+
type: s.type,
|
|
102
|
+
size: s.size,
|
|
103
|
+
...(s.type === 'file' && { mimeType: s.mimeType }),
|
|
104
|
+
}))
|
|
105
|
+
return {
|
|
106
|
+
content: [{ type: 'text', text: JSON.stringify({ results }, null, 2) }],
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/auto-drive/index.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
-
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'
|
|
3
|
-
import { z } from 'zod'
|
|
4
|
-
import { createAutoDriveHandlers } from './handlers.js'
|
|
5
|
-
|
|
6
|
-
const AUTO_DRIVE_API_KEY =
|
|
7
|
-
process.env.AUTO_DRIVE_API_KEY ??
|
|
8
|
-
(() => {
|
|
9
|
-
throw new Error('AUTO_DRIVE_API_KEY environment variable is not set')
|
|
10
|
-
})()
|
|
11
|
-
const NETWORK = process.env.NETWORK === 'taurus' ? 'taurus' : 'mainnet'
|
|
12
|
-
const ENCRYPTION_PASSWORD = process.env.ENCRYPTION_PASSWORD
|
|
13
|
-
|
|
14
|
-
const { uploadObjectHandler, downloadObjectHandler, searchObjectsHandler } =
|
|
15
|
-
createAutoDriveHandlers(AUTO_DRIVE_API_KEY, NETWORK, ENCRYPTION_PASSWORD)
|
|
16
|
-
|
|
17
|
-
export const autoDriveServer = new McpServer({ name: 'Auto Drive', version: '0.1.2' })
|
|
18
|
-
|
|
19
|
-
autoDriveServer.tool(
|
|
20
|
-
'upload-object',
|
|
21
|
-
'Upload an object permanently to the Autonomys Network using Auto Drive, any objects uploaded here will be permanently available onchain. This is useful for storing data that you want to keep forever.',
|
|
22
|
-
{
|
|
23
|
-
filename: z.string().describe('The filename to save the object as.'),
|
|
24
|
-
data: z.record(z.string(), z.any()).describe(
|
|
25
|
-
`
|
|
26
|
-
Data you want to permanently store onchain saved as a JSON object with any key-value pairs.
|
|
27
|
-
The keys are strings that describe the type of data being stored.
|
|
28
|
-
The values are the actual data being stored.
|
|
29
|
-
`,
|
|
30
|
-
),
|
|
31
|
-
} as any,
|
|
32
|
-
async ({ filename, data }, _extra): Promise<CallToolResult> => {
|
|
33
|
-
return await uploadObjectHandler({ filename, data })
|
|
34
|
-
},
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
autoDriveServer.tool(
|
|
38
|
-
'download-object',
|
|
39
|
-
'Download a text-based object (text/*, application/json) from the Autonomys Network using Auto Drive using its Content Identifier (CID).',
|
|
40
|
-
{
|
|
41
|
-
cid: z.string().describe('The Content Identifier (CID) of the object to download.'),
|
|
42
|
-
} as any,
|
|
43
|
-
async ({ cid }, _extra): Promise<CallToolResult> => {
|
|
44
|
-
return await downloadObjectHandler({ cid })
|
|
45
|
-
},
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
autoDriveServer.tool(
|
|
49
|
-
'search-objects',
|
|
50
|
-
'Search for objects on the Autonomys Network using Auto Drive by name or CID.',
|
|
51
|
-
{
|
|
52
|
-
query: z.string().describe('The name or CID fragment to search for.'),
|
|
53
|
-
} as any,
|
|
54
|
-
async ({ query }, _extra): Promise<CallToolResult> => {
|
|
55
|
-
return await searchObjectsHandler({ query })
|
|
56
|
-
},
|
|
57
|
-
)
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
+
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import { createAutoDriveHandlers } from './handlers.js'
|
|
5
|
+
|
|
6
|
+
const AUTO_DRIVE_API_KEY =
|
|
7
|
+
process.env.AUTO_DRIVE_API_KEY ??
|
|
8
|
+
(() => {
|
|
9
|
+
throw new Error('AUTO_DRIVE_API_KEY environment variable is not set')
|
|
10
|
+
})()
|
|
11
|
+
const NETWORK = process.env.NETWORK === 'taurus' ? 'taurus' : 'mainnet'
|
|
12
|
+
const ENCRYPTION_PASSWORD = process.env.ENCRYPTION_PASSWORD
|
|
13
|
+
|
|
14
|
+
const { uploadObjectHandler, downloadObjectHandler, searchObjectsHandler } =
|
|
15
|
+
createAutoDriveHandlers(AUTO_DRIVE_API_KEY, NETWORK, ENCRYPTION_PASSWORD)
|
|
16
|
+
|
|
17
|
+
export const autoDriveServer = new McpServer({ name: 'Auto Drive', version: '0.1.2' })
|
|
18
|
+
|
|
19
|
+
autoDriveServer.tool(
|
|
20
|
+
'upload-object',
|
|
21
|
+
'Upload an object permanently to the Autonomys Network using Auto Drive, any objects uploaded here will be permanently available onchain. This is useful for storing data that you want to keep forever.',
|
|
22
|
+
{
|
|
23
|
+
filename: z.string().describe('The filename to save the object as.'),
|
|
24
|
+
data: z.record(z.string(), z.any()).describe(
|
|
25
|
+
`
|
|
26
|
+
Data you want to permanently store onchain saved as a JSON object with any key-value pairs.
|
|
27
|
+
The keys are strings that describe the type of data being stored.
|
|
28
|
+
The values are the actual data being stored.
|
|
29
|
+
`,
|
|
30
|
+
),
|
|
31
|
+
} as any,
|
|
32
|
+
async ({ filename, data }, _extra): Promise<CallToolResult> => {
|
|
33
|
+
return await uploadObjectHandler({ filename, data })
|
|
34
|
+
},
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
autoDriveServer.tool(
|
|
38
|
+
'download-object',
|
|
39
|
+
'Download a text-based object (text/*, application/json) from the Autonomys Network using Auto Drive using its Content Identifier (CID).',
|
|
40
|
+
{
|
|
41
|
+
cid: z.string().describe('The Content Identifier (CID) of the object to download.'),
|
|
42
|
+
} as any,
|
|
43
|
+
async ({ cid }, _extra): Promise<CallToolResult> => {
|
|
44
|
+
return await downloadObjectHandler({ cid })
|
|
45
|
+
},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
autoDriveServer.tool(
|
|
49
|
+
'search-objects',
|
|
50
|
+
'Search for objects on the Autonomys Network using Auto Drive by name or CID.',
|
|
51
|
+
{
|
|
52
|
+
query: z.string().describe('The name or CID fragment to search for.'),
|
|
53
|
+
} as any,
|
|
54
|
+
async ({ query }, _extra): Promise<CallToolResult> => {
|
|
55
|
+
return await searchObjectsHandler({ query })
|
|
56
|
+
},
|
|
57
|
+
)
|
package/src/bin/auto-drive.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
4
|
-
import { autoDriveServer } from '../index.js'
|
|
5
|
-
|
|
6
|
-
const main = async () => {
|
|
7
|
-
const transport = new StdioServerTransport()
|
|
8
|
-
await autoDriveServer.connect(transport)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
main().catch((error) => {
|
|
12
|
-
console.error('Failed to start Auto Drive server:', error)
|
|
13
|
-
process.exit(1)
|
|
14
|
-
})
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
4
|
+
import { autoDriveServer } from '../index.js'
|
|
5
|
+
|
|
6
|
+
const main = async () => {
|
|
7
|
+
const transport = new StdioServerTransport()
|
|
8
|
+
await autoDriveServer.connect(transport)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
main().catch((error) => {
|
|
12
|
+
console.error('Failed to start Auto Drive server:', error)
|
|
13
|
+
process.exit(1)
|
|
14
|
+
})
|
package/src/bin/main.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
4
|
-
import { autoDriveServer } from '../auto-drive/index.js'
|
|
5
|
-
|
|
6
|
-
const showHelp = () => {
|
|
7
|
-
console.log(`
|
|
8
|
-
Usage: auto-mcp-servers [server-name]
|
|
9
|
-
|
|
10
|
-
Available servers:
|
|
11
|
-
auto-drive Start the Auto Drive MCP server
|
|
12
|
-
|
|
13
|
-
Environment variables:
|
|
14
|
-
For Auto Drive server:
|
|
15
|
-
AUTO_DRIVE_API_KEY API key for Auto Drive (required)
|
|
16
|
-
NETWORK 'mainnet' (default) or 'taurus'
|
|
17
|
-
ENCRYPTION_PASSWORD Password for encryption (optional)
|
|
18
|
-
`)
|
|
19
|
-
process.exit(1)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const main = async () => {
|
|
23
|
-
const serverName = process.argv[2] || 'auto-drive'
|
|
24
|
-
const transport = new StdioServerTransport()
|
|
25
|
-
|
|
26
|
-
switch (serverName) {
|
|
27
|
-
case 'auto-drive':
|
|
28
|
-
await autoDriveServer.connect(transport)
|
|
29
|
-
break
|
|
30
|
-
case 'help':
|
|
31
|
-
case '--help':
|
|
32
|
-
case '-h':
|
|
33
|
-
showHelp()
|
|
34
|
-
break
|
|
35
|
-
default:
|
|
36
|
-
console.error(`Unknown server: ${serverName}`)
|
|
37
|
-
showHelp()
|
|
38
|
-
break
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
main().catch((error) => {
|
|
43
|
-
console.error(`Failed to start MCP server:`, error)
|
|
44
|
-
process.exit(1)
|
|
45
|
-
})
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
4
|
+
import { autoDriveServer } from '../auto-drive/index.js'
|
|
5
|
+
|
|
6
|
+
const showHelp = () => {
|
|
7
|
+
console.log(`
|
|
8
|
+
Usage: auto-mcp-servers [server-name]
|
|
9
|
+
|
|
10
|
+
Available servers:
|
|
11
|
+
auto-drive Start the Auto Drive MCP server
|
|
12
|
+
|
|
13
|
+
Environment variables:
|
|
14
|
+
For Auto Drive server:
|
|
15
|
+
AUTO_DRIVE_API_KEY API key for Auto Drive (required)
|
|
16
|
+
NETWORK 'mainnet' (default) or 'taurus'
|
|
17
|
+
ENCRYPTION_PASSWORD Password for encryption (optional)
|
|
18
|
+
`)
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const main = async () => {
|
|
23
|
+
const serverName = process.argv[2] || 'auto-drive'
|
|
24
|
+
const transport = new StdioServerTransport()
|
|
25
|
+
|
|
26
|
+
switch (serverName) {
|
|
27
|
+
case 'auto-drive':
|
|
28
|
+
await autoDriveServer.connect(transport)
|
|
29
|
+
break
|
|
30
|
+
case 'help':
|
|
31
|
+
case '--help':
|
|
32
|
+
case '-h':
|
|
33
|
+
showHelp()
|
|
34
|
+
break
|
|
35
|
+
default:
|
|
36
|
+
console.error(`Unknown server: ${serverName}`)
|
|
37
|
+
showHelp()
|
|
38
|
+
break
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
main().catch((error) => {
|
|
43
|
+
console.error(`Failed to start MCP server:`, error)
|
|
44
|
+
process.exit(1)
|
|
45
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Export servers
|
|
2
|
-
export { autoDriveServer } from './auto-drive/index.js'
|
|
1
|
+
// Export servers
|
|
2
|
+
export { autoDriveServer } from './auto-drive/index.js'
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "Bundler",
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"rootDir": "./src"
|
|
8
|
-
},
|
|
9
|
-
"include": ["src/**/*"]
|
|
10
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src"
|
|
8
|
+
},
|
|
9
|
+
"include": ["src/**/*"]
|
|
10
|
+
}
|