@autonomys/auto-mcp-servers 1.4.20 → 1.4.22
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/README.md +55 -1
- package/dist/auto-drive/handlers.d.ts +1 -1
- package/dist/auto-drive/handlers.d.ts.map +1 -1
- package/dist/auto-drive/handlers.js +2 -1
- package/dist/auto-drive/index.js +3 -3
- package/dist/auto-experiences/handlers.d.ts +20 -0
- package/dist/auto-experiences/handlers.d.ts.map +1 -0
- package/dist/auto-experiences/handlers.js +96 -0
- package/dist/auto-experiences/index.d.ts +3 -0
- package/dist/auto-experiences/index.d.ts.map +1 -0
- package/dist/auto-experiences/index.js +99 -0
- package/dist/bin/auto-drive.js +1 -1
- package/dist/bin/auto-experiences.d.ts +3 -0
- package/dist/bin/auto-experiences.d.ts.map +1 -0
- package/dist/bin/auto-experiences.js +33 -0
- package/dist/bin/main.js +40 -16
- package/package.json +5 -3
- package/src/auto-drive/handlers.ts +3 -2
- package/src/auto-drive/index.ts +6 -6
- package/src/auto-experiences/handlers.ts +110 -0
- package/src/auto-experiences/index.ts +136 -0
- package/src/bin/auto-drive.ts +1 -1
- package/src/bin/auto-experiences.ts +28 -0
- package/src/bin/main.ts +39 -16
- package/src/index.ts +0 -2
package/README.md
CHANGED
|
@@ -16,6 +16,17 @@ The Auto Drive server provides the following tools:
|
|
|
16
16
|
- `download-object`: Download a text-based object (`text/*` or `application/json`) from the Autonomys network using its CID.
|
|
17
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
18
|
|
|
19
|
+
### Auto Experiences Server
|
|
20
|
+
|
|
21
|
+
The Auto Experiences server exposes functionality from the `@autonomys/auto-agents` package as MCP tools, specifically for managing agent experiences.
|
|
22
|
+
|
|
23
|
+
#### Tools
|
|
24
|
+
|
|
25
|
+
The Auto Experiences server provides the following tools:
|
|
26
|
+
|
|
27
|
+
- `save-experience`: Saves agent experience data to the Autonomys network, uploads the data to AutoDrive, and updates the last experience CID. Returns the new CID, previous CID (if any), and EVM transaction hash (if available).
|
|
28
|
+
- `retrieve-experience`: Retrieves an agent experience from the Autonomys network using its CID. Returns the full experience object including headers and data.
|
|
29
|
+
|
|
19
30
|
More servers and tools will be coming soon!
|
|
20
31
|
|
|
21
32
|
## Usage
|
|
@@ -36,6 +47,21 @@ More servers and tools will be coming soon!
|
|
|
36
47
|
"ENCRYPTION_PASSWORD": "my-password (optional)",
|
|
37
48
|
"NETWORK": "mainnet or taurus (optional, defaults to mainnet)"
|
|
38
49
|
}
|
|
50
|
+
},
|
|
51
|
+
"auto-experiences": {
|
|
52
|
+
"command": "npx",
|
|
53
|
+
"args": ["-y", "@autonomys/auto-mcp-servers", "auto-experiences"],
|
|
54
|
+
"env": {
|
|
55
|
+
"AUTO_DRIVE_API_KEY": "your-api-key",
|
|
56
|
+
"AGENT_PATH": "your-agent-path",
|
|
57
|
+
"AGENT_NAME": "your-agent-name",
|
|
58
|
+
"PRIVATE_KEY": "your-wallet-private-key",
|
|
59
|
+
"NETWORK": "mainnet or taurus (optional, defaults to mainnet)",
|
|
60
|
+
"UPLOAD_ENCRYPTION_PASSWORD": "my-password (optional)",
|
|
61
|
+
"AGENT_VERSION": "your-agent-version (optional)",
|
|
62
|
+
"RPC_URL": "your-evm-rpc-url (optional)",
|
|
63
|
+
"CONTRACT_ADDRESS": "your-contract-address (optional)"
|
|
64
|
+
}
|
|
39
65
|
}
|
|
40
66
|
}
|
|
41
67
|
}
|
|
@@ -47,7 +73,7 @@ More servers and tools will be coming soon!
|
|
|
47
73
|
|
|
48
74
|
You can use these MCP servers as tools with agent frameworks such as LangChain.
|
|
49
75
|
|
|
50
|
-
1. Install the Auto
|
|
76
|
+
1. Install the Auto MCP servers into your project:
|
|
51
77
|
|
|
52
78
|
```bash
|
|
53
79
|
npm install @autonomys/auto-mcp-servers
|
|
@@ -96,6 +122,34 @@ const result = await model
|
|
|
96
122
|
console.log(result)
|
|
97
123
|
```
|
|
98
124
|
|
|
125
|
+
3. Use the Auto Experiences server in a similar way:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Create Auto Experiences tools
|
|
129
|
+
const createAutoExperiencesTools = async (config: {
|
|
130
|
+
apiKey: string
|
|
131
|
+
agentPath: string
|
|
132
|
+
agentName: string
|
|
133
|
+
privateKey: string
|
|
134
|
+
}): Promise<StructuredToolInterface[]> => {
|
|
135
|
+
const transport = new StdioClientTransport({
|
|
136
|
+
command: process.execPath,
|
|
137
|
+
args: ['node_modules/.bin/auto-experiences-server'],
|
|
138
|
+
env: {
|
|
139
|
+
AUTO_DRIVE_API_KEY: config.apiKey,
|
|
140
|
+
AGENT_PATH: config.agentPath,
|
|
141
|
+
AGENT_NAME: config.agentName,
|
|
142
|
+
PRIVATE_KEY: config.privateKey,
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
const client = new Client({ name: 'auto-experiences', version: '0.0.1' })
|
|
147
|
+
client.connect(transport)
|
|
148
|
+
|
|
149
|
+
return await loadMcpTools('auto-experiences', client)
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
99
153
|
## License
|
|
100
154
|
|
|
101
155
|
MIT
|
|
@@ -2,7 +2,7 @@ import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
|
2
2
|
export declare const createAutoDriveHandlers: (apiKey: string, network: "taurus" | "mainnet", encryptionPassword?: string) => {
|
|
3
3
|
uploadObjectHandler: ({ filename, data, }: {
|
|
4
4
|
filename: string;
|
|
5
|
-
data: Record<string,
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
6
|
}) => Promise<CallToolResult>;
|
|
7
7
|
downloadObjectHandler: ({ cid }: {
|
|
8
8
|
cid: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/auto-drive/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE,eAAO,MAAM,uBAAuB,GAClC,QAAQ,MAAM,EACd,SAAS,QAAQ,GAAG,SAAS,EAC7B,qBAAqB,MAAM;+CAWtB;QACD,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/auto-drive/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE,eAAO,MAAM,uBAAuB,GAClC,QAAQ,MAAM,EACd,SAAS,QAAQ,GAAG,SAAS,EAC7B,qBAAqB,MAAM;+CAWtB;QACD,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC9B,KAAG,OAAO,CAAC,cAAc,CAAC;qCAIY;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,KAAG,OAAO,CAAC,cAAc,CAAC;sCAuExC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAAG,OAAO,CAAC,cAAc,CAAC;CActF,CAAA"}
|
|
@@ -92,10 +92,11 @@ export const createAutoDriveHandlers = (apiKey, network, encryptionPassword) =>
|
|
|
92
92
|
content: [
|
|
93
93
|
{
|
|
94
94
|
type: 'text',
|
|
95
|
-
text: `Error: File type
|
|
95
|
+
text: `Error: File type '${mimeType}' is not supported for direct download in this client. Only text/* and application/json are supported.`,
|
|
96
96
|
},
|
|
97
97
|
],
|
|
98
98
|
};
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
100
|
}
|
|
100
101
|
catch (error) {
|
|
101
102
|
console.error(`Failed to download object with CID ${cid}:`, error);
|
package/dist/auto-drive/index.js
CHANGED
|
@@ -25,16 +25,16 @@ autoDriveServer.tool('upload-object', 'Upload an object permanently to the Auton
|
|
|
25
25
|
The keys are strings that describe the type of data being stored.
|
|
26
26
|
The values are the actual data being stored.
|
|
27
27
|
`),
|
|
28
|
-
}, (_a
|
|
28
|
+
}, (_a) => __awaiter(void 0, [_a], void 0, function* ({ filename, data }) {
|
|
29
29
|
return yield uploadObjectHandler({ filename, data });
|
|
30
30
|
}));
|
|
31
31
|
autoDriveServer.tool('download-object', 'Download a text-based object (text/*, application/json) from the Autonomys Network using Auto Drive using its Content Identifier (CID).', {
|
|
32
32
|
cid: z.string().describe('The Content Identifier (CID) of the object to download.'),
|
|
33
|
-
}, (_a
|
|
33
|
+
}, (_a) => __awaiter(void 0, [_a], void 0, function* ({ cid }) {
|
|
34
34
|
return yield downloadObjectHandler({ cid });
|
|
35
35
|
}));
|
|
36
36
|
autoDriveServer.tool('search-objects', 'Search for objects on the Autonomys Network using Auto Drive by name or CID.', {
|
|
37
37
|
query: z.string().describe('The name or CID fragment to search for.'),
|
|
38
|
-
}, (_a
|
|
38
|
+
}, (_a) => __awaiter(void 0, [_a], void 0, function* ({ query }) {
|
|
39
39
|
return yield searchObjectsHandler({ query });
|
|
40
40
|
}));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { ExperienceManagerOptions } from '@autonomys/auto-agents/dist/experiences/types.js';
|
|
3
|
+
export declare const createExperienceHandlers: (options: ExperienceManagerOptions) => {
|
|
4
|
+
/**
|
|
5
|
+
* Saves the provided agent experience data.
|
|
6
|
+
* Uploads data to AutoDrive and updates the last experience CID.
|
|
7
|
+
* @param data - The experience data (JSON object).
|
|
8
|
+
*/
|
|
9
|
+
saveExperienceHandler: ({ data, }: {
|
|
10
|
+
data: Record<string, unknown> | unknown[] | string;
|
|
11
|
+
}) => Promise<CallToolResult>;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves an agent experience from AutoDrive using its CID.
|
|
14
|
+
* @param cid - The CID of the experience to retrieve.
|
|
15
|
+
*/
|
|
16
|
+
retrieveExperienceHandler: ({ cid }: {
|
|
17
|
+
cid: string;
|
|
18
|
+
}) => Promise<CallToolResult>;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/auto-experiences/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAGnE,OAAO,EAGL,wBAAwB,EAEzB,MAAM,kDAAkD,CAAA;AA6CzD,eAAO,MAAM,wBAAwB,GAAI,SAAS,wBAAwB;IAEtE;;;;OAIG;uCAGA;QACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,MAAM,CAAA;KACnD,KAAG,OAAO,CAAC,cAAc,CAAC;IAmB3B;;;OAGG;yCACwC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,KAAG,OAAO,CAAC,cAAc,CAAC;CAsBvF,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
// Use ExperienceManager for saving/retrieving full experiences
|
|
11
|
+
import { createExperienceManager } from '@autonomys/auto-agents';
|
|
12
|
+
// Store a singleton instance to ensure we only create one ExperienceManager
|
|
13
|
+
let experienceManagerInstance;
|
|
14
|
+
let experienceManagerPromise;
|
|
15
|
+
/**
|
|
16
|
+
* Ensures that the ExperienceManager is only created once and properly initialized.
|
|
17
|
+
* @param options Configuration options for the ExperienceManager
|
|
18
|
+
* @returns A promise that resolves to the ExperienceManager instance
|
|
19
|
+
*/
|
|
20
|
+
const getExperienceManager = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
// Return existing instance if already created
|
|
22
|
+
if (experienceManagerInstance) {
|
|
23
|
+
return experienceManagerInstance;
|
|
24
|
+
}
|
|
25
|
+
// Return in-flight promise if initialization is already in progress
|
|
26
|
+
if (experienceManagerPromise) {
|
|
27
|
+
return experienceManagerPromise;
|
|
28
|
+
}
|
|
29
|
+
// Create a new initialization promise
|
|
30
|
+
console.error('Creating ExperienceManager instance...');
|
|
31
|
+
experienceManagerPromise = createExperienceManager(options)
|
|
32
|
+
.then((manager) => {
|
|
33
|
+
console.error('ExperienceManager created successfully');
|
|
34
|
+
experienceManagerInstance = manager;
|
|
35
|
+
return manager;
|
|
36
|
+
})
|
|
37
|
+
.catch((error) => {
|
|
38
|
+
console.error('Failed to create ExperienceManager:', error);
|
|
39
|
+
// Clear promise so next call will try again
|
|
40
|
+
experienceManagerPromise = undefined;
|
|
41
|
+
throw error;
|
|
42
|
+
});
|
|
43
|
+
return experienceManagerPromise;
|
|
44
|
+
});
|
|
45
|
+
export const createExperienceHandlers = (options) => {
|
|
46
|
+
return {
|
|
47
|
+
/**
|
|
48
|
+
* Saves the provided agent experience data.
|
|
49
|
+
* Uploads data to AutoDrive and updates the last experience CID.
|
|
50
|
+
* @param data - The experience data (JSON object).
|
|
51
|
+
*/
|
|
52
|
+
saveExperienceHandler: (_a) => __awaiter(void 0, [_a], void 0, function* ({ data, }) {
|
|
53
|
+
try {
|
|
54
|
+
const experienceManager = yield getExperienceManager(options);
|
|
55
|
+
// saveExperience handles header creation, upload, and saving the latest CID
|
|
56
|
+
const result = yield experienceManager.saveExperience(data);
|
|
57
|
+
const responseText = `Experience saved successfully. CID: ${result.cid}${result.previousCid ? `, Previous CID: ${result.previousCid}` : ''}${result.evmHash ? `, EVM Tx: ${result.evmHash}` : ', EVM save skipped/failed.'}`;
|
|
58
|
+
return { content: [{ type: 'text', text: responseText }] };
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error('Failed to save experience:', error);
|
|
63
|
+
return {
|
|
64
|
+
isError: true,
|
|
65
|
+
content: [{ type: 'text', text: `Error saving experience: ${error.message}` }],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}),
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves an agent experience from AutoDrive using its CID.
|
|
71
|
+
* @param cid - The CID of the experience to retrieve.
|
|
72
|
+
*/
|
|
73
|
+
retrieveExperienceHandler: (_a) => __awaiter(void 0, [_a], void 0, function* ({ cid }) {
|
|
74
|
+
var _b;
|
|
75
|
+
try {
|
|
76
|
+
const experienceManager = yield getExperienceManager(options);
|
|
77
|
+
// retrieveExperience handles download and potential retries
|
|
78
|
+
const experience = yield experienceManager.retrieveExperience(cid);
|
|
79
|
+
// Return the full experience object (header + data or V0 structure) as JSON string
|
|
80
|
+
return { content: [{ type: 'text', text: JSON.stringify(experience, null, 2) }] };
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error(`Failed to retrieve experience for CID ${cid}:`, error);
|
|
85
|
+
// Provide more specific error if possible (e.g., Not Found)
|
|
86
|
+
const errorMessage = ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Not Found'))
|
|
87
|
+
? `Experience not found for CID: ${cid}`
|
|
88
|
+
: `Error retrieving experience: ${error.message}`;
|
|
89
|
+
return {
|
|
90
|
+
isError: true,
|
|
91
|
+
content: [{ type: 'text', text: errorMessage }],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}),
|
|
95
|
+
};
|
|
96
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auto-experiences/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAyEnE,eAAO,MAAM,qBAAqB,WAAgE,CAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { createExperienceHandlers } from './handlers.js';
|
|
14
|
+
// AutoDrive Config
|
|
15
|
+
const AUTO_DRIVE_API_KEY = (_a = process.env.AUTO_DRIVE_API_KEY) !== null && _a !== void 0 ? _a : (() => {
|
|
16
|
+
throw new Error('AUTO_DRIVE_API_KEY env var missing');
|
|
17
|
+
})();
|
|
18
|
+
const NETWORK = process.env.NETWORK === 'taurus' ? 'taurus' : 'mainnet';
|
|
19
|
+
const UPLOAD_ENCRYPTION_PASSWORD = process.env.UPLOAD_ENCRYPTION_PASSWORD;
|
|
20
|
+
// Agent Config
|
|
21
|
+
const AGENT_PATH = (_b = process.env.AGENT_PATH) !== null && _b !== void 0 ? _b : (() => {
|
|
22
|
+
throw new Error('AGENT_PATH env var missing');
|
|
23
|
+
})();
|
|
24
|
+
const AGENT_NAME = (_c = process.env.AGENT_NAME) !== null && _c !== void 0 ? _c : (() => {
|
|
25
|
+
throw new Error('AGENT_NAME env var missing');
|
|
26
|
+
})();
|
|
27
|
+
const AGENT_VERSION = process.env.AGENT_VERSION; // Optional
|
|
28
|
+
// Wallet / EVM Config
|
|
29
|
+
const RPC_URL = process.env.RPC_URL;
|
|
30
|
+
const PRIVATE_KEY = process.env.PRIVATE_KEY;
|
|
31
|
+
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS;
|
|
32
|
+
// Construct ExperienceManagerOptions
|
|
33
|
+
const experienceManagerOptions = {
|
|
34
|
+
autoDriveApiOptions: {
|
|
35
|
+
apiKey: AUTO_DRIVE_API_KEY,
|
|
36
|
+
network: NETWORK,
|
|
37
|
+
},
|
|
38
|
+
agentOptions: Object.assign({ agentPath: AGENT_PATH, agentName: AGENT_NAME }, (AGENT_VERSION && { agentVersion: AGENT_VERSION })),
|
|
39
|
+
// Wallet options are required by ExperienceManager for signing uploads, even if EVM isn't used for CID storage
|
|
40
|
+
walletOptions: Object.assign(Object.assign({}, (RPC_URL && CONTRACT_ADDRESS
|
|
41
|
+
? {
|
|
42
|
+
contractInfo: {
|
|
43
|
+
rpcUrl: RPC_URL,
|
|
44
|
+
contractAddress: CONTRACT_ADDRESS,
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
: {})), { privateKey: PRIVATE_KEY !== null && PRIVATE_KEY !== void 0 ? PRIVATE_KEY : (() => {
|
|
48
|
+
throw new Error('PRIVATE_KEY env var missing');
|
|
49
|
+
})() }),
|
|
50
|
+
// Ensure uploadOptions is always present and includes required fields
|
|
51
|
+
uploadOptions: Object.assign(Object.assign({}, (UPLOAD_ENCRYPTION_PASSWORD && { password: UPLOAD_ENCRYPTION_PASSWORD })), { compression: true }),
|
|
52
|
+
};
|
|
53
|
+
// Check if EVM details are partially missing for CID storage, Wallet is still needed for signing
|
|
54
|
+
if (!RPC_URL || !CONTRACT_ADDRESS) {
|
|
55
|
+
console.error('EVM environment variables (RPC_URL, CONTRACT_ADDRESS) not fully set. Experience manager will operate in offline mode with local-only CID storage. Wallet private key IS still required for signing uploads.');
|
|
56
|
+
}
|
|
57
|
+
// Create MCP Server
|
|
58
|
+
export const autoExperiencesServer = new McpServer({ name: 'Auto Experiences', version: '0.1.0' });
|
|
59
|
+
// Initialize handlers - now fully synchronous with internal async management
|
|
60
|
+
console.error('Initializing Auto Experiences Handlers...');
|
|
61
|
+
const { saveExperienceHandler, retrieveExperienceHandler } = createExperienceHandlers(experienceManagerOptions);
|
|
62
|
+
// Register save-experience tool with a simpler, more permissive schema
|
|
63
|
+
autoExperiencesServer.tool('save-experience', 'Saves the provided agent experience data. Uploads to AutoDrive and updates the last experience CID.', {
|
|
64
|
+
// Using a simpler schema that's more compatible across clients
|
|
65
|
+
data: z
|
|
66
|
+
.object({})
|
|
67
|
+
.passthrough()
|
|
68
|
+
.optional()
|
|
69
|
+
.describe('The experience data to save. Can be any JSON object with fields like title, description, etc.'),
|
|
70
|
+
}, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
try {
|
|
72
|
+
console.error('save-experience received args:', JSON.stringify(args));
|
|
73
|
+
// If data is missing entirely, use empty object
|
|
74
|
+
const inputData = (args === null || args === void 0 ? void 0 : args.data) || {};
|
|
75
|
+
console.error('Processed data for save:', JSON.stringify(inputData));
|
|
76
|
+
return yield saveExperienceHandler({ data: inputData });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
80
|
+
console.error('Error in save-experience tool:', errorMessage);
|
|
81
|
+
return {
|
|
82
|
+
isError: true,
|
|
83
|
+
content: [{ type: 'text', text: `Error processing save request: ${errorMessage}` }],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
87
|
+
// Register retrieve-experience tool
|
|
88
|
+
autoExperiencesServer.tool('retrieve-experience', 'Retrieves an agent experience from AutoDrive using its CID.', {
|
|
89
|
+
cid: z.string().describe('The Content Identifier (CID) string of the experience to retrieve.'),
|
|
90
|
+
}, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
if (!args.cid) {
|
|
92
|
+
return {
|
|
93
|
+
isError: true,
|
|
94
|
+
content: [{ type: 'text', text: 'Error: Missing required cid parameter' }],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return yield retrieveExperienceHandler({ cid: args.cid });
|
|
98
|
+
}));
|
|
99
|
+
console.error('Auto Experiences MCP tools registered.');
|
package/dist/bin/auto-drive.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
12
|
-
import { autoDriveServer } from '../index.js';
|
|
12
|
+
import { autoDriveServer } from '../auto-drive/index.js';
|
|
13
13
|
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
14
|
const transport = new StdioServerTransport();
|
|
15
15
|
yield autoDriveServer.connect(transport);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-experiences.d.ts","sourceRoot":"","sources":["../../src/bin/auto-experiences.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
12
|
+
// Import directly from the root index file
|
|
13
|
+
import { autoExperiencesServer } from '../auto-experiences/index.js';
|
|
14
|
+
// Main function with improved error handling and process management
|
|
15
|
+
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
console.error('Starting Auto Experiences MCP server...');
|
|
18
|
+
// Create transport
|
|
19
|
+
const transport = new StdioServerTransport();
|
|
20
|
+
// Connect to transport (this initiates message handling)
|
|
21
|
+
yield autoExperiencesServer.connect(transport);
|
|
22
|
+
console.error('Auto Experiences server running and ready to accept requests');
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error('Failed to start Auto Experiences server:', error);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
// Execute main function with global error handling
|
|
30
|
+
main().catch((error) => {
|
|
31
|
+
console.error('Unhandled error in main():', error);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
});
|
package/dist/bin/main.js
CHANGED
|
@@ -10,40 +10,64 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
12
12
|
import { autoDriveServer } from '../auto-drive/index.js';
|
|
13
|
+
import { autoExperiencesServer } from '../auto-experiences/index.js';
|
|
13
14
|
const showHelp = () => {
|
|
14
|
-
console.
|
|
15
|
+
console.error(`
|
|
15
16
|
Usage: auto-mcp-servers [server-name]
|
|
16
17
|
|
|
17
18
|
Available servers:
|
|
18
|
-
auto-drive
|
|
19
|
+
auto-drive Start the Auto Drive MCP server
|
|
20
|
+
auto-experiences Start the Auto Experiences MCP server
|
|
19
21
|
|
|
20
22
|
Environment variables:
|
|
21
23
|
For Auto Drive server:
|
|
22
24
|
AUTO_DRIVE_API_KEY API key for Auto Drive (required)
|
|
23
25
|
NETWORK 'mainnet' (default) or 'taurus'
|
|
24
26
|
ENCRYPTION_PASSWORD Password for encryption (optional)
|
|
27
|
+
|
|
28
|
+
For Auto Experiences server:
|
|
29
|
+
AUTO_DRIVE_API_KEY API key for Auto Drive (required)
|
|
30
|
+
NETWORK 'mainnet' (default) or 'taurus'
|
|
31
|
+
UPLOAD_ENCRYPTION_PASSWORD Password for encryption (optional)
|
|
32
|
+
AGENT_PATH Path to agent (required)
|
|
33
|
+
AGENT_NAME Name of agent (required)
|
|
34
|
+
AGENT_VERSION Version of agent (optional)
|
|
35
|
+
PRIVATE_KEY Wallet private key (required)
|
|
36
|
+
RPC_URL EVM RPC URL (optional)
|
|
37
|
+
CONTRACT_ADDRESS Contract address (optional)
|
|
25
38
|
`);
|
|
26
39
|
process.exit(1);
|
|
27
40
|
};
|
|
28
41
|
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
42
|
const serverName = process.argv[2] || 'auto-drive';
|
|
30
43
|
const transport = new StdioServerTransport();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
try {
|
|
45
|
+
switch (serverName) {
|
|
46
|
+
case 'auto-drive':
|
|
47
|
+
console.error('Starting Auto Drive MCP server...');
|
|
48
|
+
yield autoDriveServer.connect(transport);
|
|
49
|
+
break;
|
|
50
|
+
case 'auto-experiences':
|
|
51
|
+
console.error('Starting Auto Experiences MCP server...');
|
|
52
|
+
yield autoExperiencesServer.connect(transport);
|
|
53
|
+
break;
|
|
54
|
+
case 'help':
|
|
55
|
+
case '--help':
|
|
56
|
+
case '-h':
|
|
57
|
+
showHelp();
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
console.error(`Unknown server: ${serverName}`);
|
|
61
|
+
showHelp();
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error(`Failed to start ${serverName} server:`, error);
|
|
67
|
+
process.exit(1);
|
|
44
68
|
}
|
|
45
69
|
});
|
|
46
70
|
main().catch((error) => {
|
|
47
|
-
console.error(
|
|
71
|
+
console.error('Failed to start MCP server:', error);
|
|
48
72
|
process.exit(1);
|
|
49
73
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-mcp-servers",
|
|
3
3
|
"packageManager": "yarn@4.7.0",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.22",
|
|
5
5
|
"description": "Autonomys Network MCP servers",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"main": "dist/index.js",
|
|
20
20
|
"bin": {
|
|
21
21
|
"auto-drive-server": "./dist/bin/auto-drive.js",
|
|
22
|
+
"auto-experiences-server": "./dist/bin/auto-experiences.js",
|
|
22
23
|
"auto-mcp-servers": "./dist/bin/main.js"
|
|
23
24
|
},
|
|
24
25
|
"scripts": {
|
|
@@ -30,7 +31,8 @@
|
|
|
30
31
|
"server"
|
|
31
32
|
],
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@autonomys/auto-
|
|
34
|
+
"@autonomys/auto-agents": "^1.4.22",
|
|
35
|
+
"@autonomys/auto-drive": "^1.4.22",
|
|
34
36
|
"@modelcontextprotocol/sdk": "^1.9.0",
|
|
35
37
|
"zod": "^3.24.2"
|
|
36
38
|
},
|
|
@@ -39,5 +41,5 @@
|
|
|
39
41
|
"ts-node": "^10.9.1",
|
|
40
42
|
"typescript": "^5.8.3"
|
|
41
43
|
},
|
|
42
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "ef4c21d683cad697f7015e52becd399a8ca2ed84"
|
|
43
45
|
}
|
|
@@ -18,7 +18,7 @@ export const createAutoDriveHandlers = (
|
|
|
18
18
|
data,
|
|
19
19
|
}: {
|
|
20
20
|
filename: string
|
|
21
|
-
data: Record<string,
|
|
21
|
+
data: Record<string, unknown>
|
|
22
22
|
}): Promise<CallToolResult> => {
|
|
23
23
|
const cid = await autoDriveApi.uploadObjectAsJSON({ data }, filename, uploadOptions)
|
|
24
24
|
return { content: [{ type: 'text', text: `Object uploaded successfully with ${cid}` }] }
|
|
@@ -80,10 +80,11 @@ export const createAutoDriveHandlers = (
|
|
|
80
80
|
content: [
|
|
81
81
|
{
|
|
82
82
|
type: 'text',
|
|
83
|
-
text: `Error: File type
|
|
83
|
+
text: `Error: File type '${mimeType}' is not supported for direct download in this client. Only text/* and application/json are supported.`,
|
|
84
84
|
},
|
|
85
85
|
],
|
|
86
86
|
}
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
88
|
} catch (error: any) {
|
|
88
89
|
console.error(`Failed to download object with CID ${cid}:`, error)
|
|
89
90
|
const errorMessage = error.message || 'Unknown error occurred during download.'
|
package/src/auto-drive/index.ts
CHANGED
|
@@ -28,8 +28,8 @@ autoDriveServer.tool(
|
|
|
28
28
|
The values are the actual data being stored.
|
|
29
29
|
`,
|
|
30
30
|
),
|
|
31
|
-
}
|
|
32
|
-
async ({ filename, data }
|
|
31
|
+
},
|
|
32
|
+
async ({ filename, data }): Promise<CallToolResult> => {
|
|
33
33
|
return await uploadObjectHandler({ filename, data })
|
|
34
34
|
},
|
|
35
35
|
)
|
|
@@ -39,8 +39,8 @@ autoDriveServer.tool(
|
|
|
39
39
|
'Download a text-based object (text/*, application/json) from the Autonomys Network using Auto Drive using its Content Identifier (CID).',
|
|
40
40
|
{
|
|
41
41
|
cid: z.string().describe('The Content Identifier (CID) of the object to download.'),
|
|
42
|
-
}
|
|
43
|
-
async ({ cid }
|
|
42
|
+
},
|
|
43
|
+
async ({ cid }): Promise<CallToolResult> => {
|
|
44
44
|
return await downloadObjectHandler({ cid })
|
|
45
45
|
},
|
|
46
46
|
)
|
|
@@ -50,8 +50,8 @@ autoDriveServer.tool(
|
|
|
50
50
|
'Search for objects on the Autonomys Network using Auto Drive by name or CID.',
|
|
51
51
|
{
|
|
52
52
|
query: z.string().describe('The name or CID fragment to search for.'),
|
|
53
|
-
}
|
|
54
|
-
async ({ query }
|
|
53
|
+
},
|
|
54
|
+
async ({ query }): Promise<CallToolResult> => {
|
|
55
55
|
return await searchObjectsHandler({ query })
|
|
56
56
|
},
|
|
57
57
|
)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'
|
|
2
|
+
// Use ExperienceManager for saving/retrieving full experiences
|
|
3
|
+
import { createExperienceManager } from '@autonomys/auto-agents'
|
|
4
|
+
import {
|
|
5
|
+
AgentExperience,
|
|
6
|
+
AgentExperienceV0,
|
|
7
|
+
ExperienceManagerOptions,
|
|
8
|
+
ExperienceSaveResult,
|
|
9
|
+
} from '@autonomys/auto-agents/dist/experiences/types.js'
|
|
10
|
+
|
|
11
|
+
// Define a type for the ExperienceManager to help with typing
|
|
12
|
+
type ExperienceManager = Awaited<ReturnType<typeof createExperienceManager>>
|
|
13
|
+
|
|
14
|
+
// Store a singleton instance to ensure we only create one ExperienceManager
|
|
15
|
+
let experienceManagerInstance: ExperienceManager | undefined
|
|
16
|
+
let experienceManagerPromise: Promise<ExperienceManager> | undefined
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Ensures that the ExperienceManager is only created once and properly initialized.
|
|
20
|
+
* @param options Configuration options for the ExperienceManager
|
|
21
|
+
* @returns A promise that resolves to the ExperienceManager instance
|
|
22
|
+
*/
|
|
23
|
+
const getExperienceManager = async (
|
|
24
|
+
options: ExperienceManagerOptions,
|
|
25
|
+
): Promise<ExperienceManager> => {
|
|
26
|
+
// Return existing instance if already created
|
|
27
|
+
if (experienceManagerInstance) {
|
|
28
|
+
return experienceManagerInstance
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Return in-flight promise if initialization is already in progress
|
|
32
|
+
if (experienceManagerPromise) {
|
|
33
|
+
return experienceManagerPromise
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Create a new initialization promise
|
|
37
|
+
console.error('Creating ExperienceManager instance...')
|
|
38
|
+
experienceManagerPromise = createExperienceManager(options)
|
|
39
|
+
.then((manager) => {
|
|
40
|
+
console.error('ExperienceManager created successfully')
|
|
41
|
+
experienceManagerInstance = manager
|
|
42
|
+
return manager
|
|
43
|
+
})
|
|
44
|
+
.catch((error) => {
|
|
45
|
+
console.error('Failed to create ExperienceManager:', error)
|
|
46
|
+
// Clear promise so next call will try again
|
|
47
|
+
experienceManagerPromise = undefined
|
|
48
|
+
throw error
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return experienceManagerPromise
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const createExperienceHandlers = (options: ExperienceManagerOptions) => {
|
|
55
|
+
return {
|
|
56
|
+
/**
|
|
57
|
+
* Saves the provided agent experience data.
|
|
58
|
+
* Uploads data to AutoDrive and updates the last experience CID.
|
|
59
|
+
* @param data - The experience data (JSON object).
|
|
60
|
+
*/
|
|
61
|
+
saveExperienceHandler: async ({
|
|
62
|
+
data,
|
|
63
|
+
}: {
|
|
64
|
+
data: Record<string, unknown> | unknown[] | string // Allow object or array data
|
|
65
|
+
}): Promise<CallToolResult> => {
|
|
66
|
+
try {
|
|
67
|
+
const experienceManager = await getExperienceManager(options)
|
|
68
|
+
// saveExperience handles header creation, upload, and saving the latest CID
|
|
69
|
+
const result: ExperienceSaveResult = await experienceManager.saveExperience(data)
|
|
70
|
+
const responseText = `Experience saved successfully. CID: ${result.cid}${
|
|
71
|
+
result.previousCid ? `, Previous CID: ${result.previousCid}` : ''
|
|
72
|
+
}${result.evmHash ? `, EVM Tx: ${result.evmHash}` : ', EVM save skipped/failed.'}`
|
|
73
|
+
return { content: [{ type: 'text', text: responseText }] }
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
} catch (error: any) {
|
|
76
|
+
console.error('Failed to save experience:', error)
|
|
77
|
+
return {
|
|
78
|
+
isError: true,
|
|
79
|
+
content: [{ type: 'text', text: `Error saving experience: ${error.message}` }],
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Retrieves an agent experience from AutoDrive using its CID.
|
|
86
|
+
* @param cid - The CID of the experience to retrieve.
|
|
87
|
+
*/
|
|
88
|
+
retrieveExperienceHandler: async ({ cid }: { cid: string }): Promise<CallToolResult> => {
|
|
89
|
+
try {
|
|
90
|
+
const experienceManager = await getExperienceManager(options)
|
|
91
|
+
// retrieveExperience handles download and potential retries
|
|
92
|
+
const experience: AgentExperience | AgentExperienceV0 =
|
|
93
|
+
await experienceManager.retrieveExperience(cid)
|
|
94
|
+
// Return the full experience object (header + data or V0 structure) as JSON string
|
|
95
|
+
return { content: [{ type: 'text', text: JSON.stringify(experience, null, 2) }] }
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
} catch (error: any) {
|
|
98
|
+
console.error(`Failed to retrieve experience for CID ${cid}:`, error)
|
|
99
|
+
// Provide more specific error if possible (e.g., Not Found)
|
|
100
|
+
const errorMessage = error.message?.includes('Not Found')
|
|
101
|
+
? `Experience not found for CID: ${cid}`
|
|
102
|
+
: `Error retrieving experience: ${error.message}`
|
|
103
|
+
return {
|
|
104
|
+
isError: true,
|
|
105
|
+
content: [{ type: 'text', text: errorMessage }],
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { ExperienceManagerOptions } from '@autonomys/auto-agents'
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import { createExperienceHandlers } from './handlers.js'
|
|
5
|
+
|
|
6
|
+
// AutoDrive Config
|
|
7
|
+
const AUTO_DRIVE_API_KEY =
|
|
8
|
+
process.env.AUTO_DRIVE_API_KEY ??
|
|
9
|
+
(() => {
|
|
10
|
+
throw new Error('AUTO_DRIVE_API_KEY env var missing')
|
|
11
|
+
})()
|
|
12
|
+
const NETWORK = process.env.NETWORK === 'taurus' ? 'taurus' : 'mainnet'
|
|
13
|
+
const UPLOAD_ENCRYPTION_PASSWORD = process.env.UPLOAD_ENCRYPTION_PASSWORD
|
|
14
|
+
|
|
15
|
+
// Agent Config
|
|
16
|
+
const AGENT_PATH =
|
|
17
|
+
process.env.AGENT_PATH ??
|
|
18
|
+
(() => {
|
|
19
|
+
throw new Error('AGENT_PATH env var missing')
|
|
20
|
+
})()
|
|
21
|
+
const AGENT_NAME =
|
|
22
|
+
process.env.AGENT_NAME ??
|
|
23
|
+
(() => {
|
|
24
|
+
throw new Error('AGENT_NAME env var missing')
|
|
25
|
+
})()
|
|
26
|
+
const AGENT_VERSION = process.env.AGENT_VERSION // Optional
|
|
27
|
+
|
|
28
|
+
// Wallet / EVM Config
|
|
29
|
+
const RPC_URL = process.env.RPC_URL
|
|
30
|
+
const PRIVATE_KEY = process.env.PRIVATE_KEY
|
|
31
|
+
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS
|
|
32
|
+
|
|
33
|
+
// Construct ExperienceManagerOptions
|
|
34
|
+
const experienceManagerOptions: ExperienceManagerOptions = {
|
|
35
|
+
autoDriveApiOptions: {
|
|
36
|
+
apiKey: AUTO_DRIVE_API_KEY,
|
|
37
|
+
network: NETWORK,
|
|
38
|
+
},
|
|
39
|
+
agentOptions: {
|
|
40
|
+
agentPath: AGENT_PATH,
|
|
41
|
+
agentName: AGENT_NAME,
|
|
42
|
+
...(AGENT_VERSION && { agentVersion: AGENT_VERSION }),
|
|
43
|
+
},
|
|
44
|
+
// Wallet options are required by ExperienceManager for signing uploads, even if EVM isn't used for CID storage
|
|
45
|
+
walletOptions: {
|
|
46
|
+
...(RPC_URL && CONTRACT_ADDRESS
|
|
47
|
+
? {
|
|
48
|
+
contractInfo: {
|
|
49
|
+
rpcUrl: RPC_URL,
|
|
50
|
+
contractAddress: CONTRACT_ADDRESS,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
: {}),
|
|
54
|
+
privateKey:
|
|
55
|
+
PRIVATE_KEY ??
|
|
56
|
+
(() => {
|
|
57
|
+
throw new Error('PRIVATE_KEY env var missing')
|
|
58
|
+
})(),
|
|
59
|
+
},
|
|
60
|
+
// Ensure uploadOptions is always present and includes required fields
|
|
61
|
+
uploadOptions: {
|
|
62
|
+
...(UPLOAD_ENCRYPTION_PASSWORD && { password: UPLOAD_ENCRYPTION_PASSWORD }),
|
|
63
|
+
compression: true,
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Check if EVM details are partially missing for CID storage, Wallet is still needed for signing
|
|
68
|
+
if (!RPC_URL || !CONTRACT_ADDRESS) {
|
|
69
|
+
console.error(
|
|
70
|
+
'EVM environment variables (RPC_URL, CONTRACT_ADDRESS) not fully set. Experience manager will operate in offline mode with local-only CID storage. Wallet private key IS still required for signing uploads.',
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Create MCP Server
|
|
75
|
+
export const autoExperiencesServer = new McpServer({ name: 'Auto Experiences', version: '0.1.0' })
|
|
76
|
+
|
|
77
|
+
// Initialize handlers - now fully synchronous with internal async management
|
|
78
|
+
console.error('Initializing Auto Experiences Handlers...')
|
|
79
|
+
const { saveExperienceHandler, retrieveExperienceHandler } =
|
|
80
|
+
createExperienceHandlers(experienceManagerOptions)
|
|
81
|
+
|
|
82
|
+
// Register save-experience tool with a simpler, more permissive schema
|
|
83
|
+
autoExperiencesServer.tool(
|
|
84
|
+
'save-experience',
|
|
85
|
+
'Saves the provided agent experience data. Uploads to AutoDrive and updates the last experience CID.',
|
|
86
|
+
{
|
|
87
|
+
// Using a simpler schema that's more compatible across clients
|
|
88
|
+
data: z
|
|
89
|
+
.object({})
|
|
90
|
+
.passthrough()
|
|
91
|
+
.optional()
|
|
92
|
+
.describe(
|
|
93
|
+
'The experience data to save. Can be any JSON object with fields like title, description, etc.',
|
|
94
|
+
),
|
|
95
|
+
},
|
|
96
|
+
async (args) => {
|
|
97
|
+
try {
|
|
98
|
+
console.error('save-experience received args:', JSON.stringify(args))
|
|
99
|
+
|
|
100
|
+
// If data is missing entirely, use empty object
|
|
101
|
+
const inputData = args?.data || {}
|
|
102
|
+
|
|
103
|
+
console.error('Processed data for save:', JSON.stringify(inputData))
|
|
104
|
+
|
|
105
|
+
return await saveExperienceHandler({ data: inputData })
|
|
106
|
+
} catch (error) {
|
|
107
|
+
const errorMessage = error instanceof Error ? error.message : String(error)
|
|
108
|
+
console.error('Error in save-experience tool:', errorMessage)
|
|
109
|
+
return {
|
|
110
|
+
isError: true,
|
|
111
|
+
content: [{ type: 'text', text: `Error processing save request: ${errorMessage}` }],
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
// Register retrieve-experience tool
|
|
118
|
+
autoExperiencesServer.tool(
|
|
119
|
+
'retrieve-experience',
|
|
120
|
+
'Retrieves an agent experience from AutoDrive using its CID.',
|
|
121
|
+
{
|
|
122
|
+
cid: z.string().describe('The Content Identifier (CID) string of the experience to retrieve.'),
|
|
123
|
+
},
|
|
124
|
+
async (args: { cid?: string }) => {
|
|
125
|
+
if (!args.cid) {
|
|
126
|
+
return {
|
|
127
|
+
isError: true,
|
|
128
|
+
content: [{ type: 'text', text: 'Error: Missing required cid parameter' }],
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return await retrieveExperienceHandler({ cid: args.cid })
|
|
133
|
+
},
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
console.error('Auto Experiences MCP tools registered.')
|
package/src/bin/auto-drive.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
4
|
-
import { autoDriveServer } from '../index.js'
|
|
4
|
+
import { autoDriveServer } from '../auto-drive/index.js'
|
|
5
5
|
|
|
6
6
|
const main = async () => {
|
|
7
7
|
const transport = new StdioServerTransport()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
4
|
+
// Import directly from the root index file
|
|
5
|
+
import { autoExperiencesServer } from '../auto-experiences/index.js'
|
|
6
|
+
|
|
7
|
+
// Main function with improved error handling and process management
|
|
8
|
+
const main = async () => {
|
|
9
|
+
try {
|
|
10
|
+
console.error('Starting Auto Experiences MCP server...')
|
|
11
|
+
|
|
12
|
+
// Create transport
|
|
13
|
+
const transport = new StdioServerTransport()
|
|
14
|
+
|
|
15
|
+
// Connect to transport (this initiates message handling)
|
|
16
|
+
await autoExperiencesServer.connect(transport)
|
|
17
|
+
console.error('Auto Experiences server running and ready to accept requests')
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('Failed to start Auto Experiences server:', error)
|
|
20
|
+
process.exit(1)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Execute main function with global error handling
|
|
25
|
+
main().catch((error) => {
|
|
26
|
+
console.error('Unhandled error in main():', error)
|
|
27
|
+
process.exit(1)
|
|
28
|
+
})
|
package/src/bin/main.ts
CHANGED
|
@@ -2,19 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
4
4
|
import { autoDriveServer } from '../auto-drive/index.js'
|
|
5
|
+
import { autoExperiencesServer } from '../auto-experiences/index.js'
|
|
5
6
|
|
|
6
7
|
const showHelp = () => {
|
|
7
|
-
console.
|
|
8
|
+
console.error(`
|
|
8
9
|
Usage: auto-mcp-servers [server-name]
|
|
9
10
|
|
|
10
11
|
Available servers:
|
|
11
|
-
auto-drive
|
|
12
|
+
auto-drive Start the Auto Drive MCP server
|
|
13
|
+
auto-experiences Start the Auto Experiences MCP server
|
|
12
14
|
|
|
13
15
|
Environment variables:
|
|
14
16
|
For Auto Drive server:
|
|
15
17
|
AUTO_DRIVE_API_KEY API key for Auto Drive (required)
|
|
16
18
|
NETWORK 'mainnet' (default) or 'taurus'
|
|
17
19
|
ENCRYPTION_PASSWORD Password for encryption (optional)
|
|
20
|
+
|
|
21
|
+
For Auto Experiences server:
|
|
22
|
+
AUTO_DRIVE_API_KEY API key for Auto Drive (required)
|
|
23
|
+
NETWORK 'mainnet' (default) or 'taurus'
|
|
24
|
+
UPLOAD_ENCRYPTION_PASSWORD Password for encryption (optional)
|
|
25
|
+
AGENT_PATH Path to agent (required)
|
|
26
|
+
AGENT_NAME Name of agent (required)
|
|
27
|
+
AGENT_VERSION Version of agent (optional)
|
|
28
|
+
PRIVATE_KEY Wallet private key (required)
|
|
29
|
+
RPC_URL EVM RPC URL (optional)
|
|
30
|
+
CONTRACT_ADDRESS Contract address (optional)
|
|
18
31
|
`)
|
|
19
32
|
process.exit(1)
|
|
20
33
|
}
|
|
@@ -23,23 +36,33 @@ const main = async () => {
|
|
|
23
36
|
const serverName = process.argv[2] || 'auto-drive'
|
|
24
37
|
const transport = new StdioServerTransport()
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
try {
|
|
40
|
+
switch (serverName) {
|
|
41
|
+
case 'auto-drive':
|
|
42
|
+
console.error('Starting Auto Drive MCP server...')
|
|
43
|
+
await autoDriveServer.connect(transport)
|
|
44
|
+
break
|
|
45
|
+
case 'auto-experiences':
|
|
46
|
+
console.error('Starting Auto Experiences MCP server...')
|
|
47
|
+
await autoExperiencesServer.connect(transport)
|
|
48
|
+
break
|
|
49
|
+
case 'help':
|
|
50
|
+
case '--help':
|
|
51
|
+
case '-h':
|
|
52
|
+
showHelp()
|
|
53
|
+
break
|
|
54
|
+
default:
|
|
55
|
+
console.error(`Unknown server: ${serverName}`)
|
|
56
|
+
showHelp()
|
|
57
|
+
break
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error(`Failed to start ${serverName} server:`, error)
|
|
61
|
+
process.exit(1)
|
|
39
62
|
}
|
|
40
63
|
}
|
|
41
64
|
|
|
42
65
|
main().catch((error) => {
|
|
43
|
-
console.error(
|
|
66
|
+
console.error('Failed to start MCP server:', error)
|
|
44
67
|
process.exit(1)
|
|
45
68
|
})
|
package/src/index.ts
DELETED