cornerstone-autonomous-agent 2.0.0 → 2.1.0
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/.env.example +3 -8
- package/LICENSE.md +384 -384
- package/README.md +27 -27
- package/adapters/local/README.md +2 -2
- package/adapters/openai/openapi.yaml +3 -3
- package/adapters/openclaw/SKILL.md +40 -29
- package/package.json +4 -4
- package/skills/README.md +1 -1
- package/skills/autonomous-agent/SKILL.md +41 -30
- package/src/agent/agent.js +77 -53
- package/src/agent/tools/localTools.js +260 -259
- package/src/agent/tools/mcpTools.js +150 -150
- package/src/cli.js +1 -1
- package/src/lib/aptos/signPayment.js +1 -1
- package/src/lib/evm/signPayment.js +1 -1
- package/src/lib/mcp/client.js +35 -17
- package/src/run-agent.js +2 -2
- package/src/show-agent-addresses.js +33 -33
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP tools as LangChain tools: run_prediction, run_backtest, link_bank_account,
|
|
3
|
-
* get_agent_reputation_score, get_borrower_score, get_agent_reputation_score_by_email, get_borrower_score_by_email.
|
|
4
|
-
* Each invokes mcpClient.callTool(name, args) with x402 retry inside the client.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { tool } from '@langchain/core/tools';
|
|
8
|
-
import { z } from 'zod';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {{ callTool: (name: string, args: Object) => Promise<Object> }} mcpClient - from createMcpClient()
|
|
12
|
-
* @returns {import('@langchain/core/tools').StructuredToolInterface[]}
|
|
13
|
-
*/
|
|
14
|
-
export function createMcpTools(mcpClient) {
|
|
15
|
-
const run_prediction = tool(
|
|
16
|
-
async ({ symbol, horizon }) => {
|
|
17
|
-
console.log(`Calling run_prediction: symbol=${symbol}, horizon=${horizon}`);
|
|
18
|
-
const out = await mcpClient.callTool('run_prediction', {
|
|
19
|
-
symbol: symbol || 'AAPL',
|
|
20
|
-
horizon: horizon ?? 30,
|
|
21
|
-
});
|
|
22
|
-
console.log('MCP response:', JSON.stringify(out, null, 2));
|
|
23
|
-
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: 'run_prediction',
|
|
27
|
-
description: 'Run stock prediction for a ticker. Returns
|
|
28
|
-
schema: z.object({
|
|
29
|
-
symbol: z.string().describe('Stock symbol (e.g. AAPL)'),
|
|
30
|
-
horizon: z.number().default(30).describe('Prediction horizon in days'),
|
|
31
|
-
}),
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const run_backtest = tool(
|
|
36
|
-
async ({ symbol, startDate, endDate, strategy }) => {
|
|
37
|
-
const out = await mcpClient.callTool('run_backtest', {
|
|
38
|
-
symbol: symbol || 'AAPL',
|
|
39
|
-
startDate: startDate || '',
|
|
40
|
-
endDate: endDate || '',
|
|
41
|
-
strategy: strategy || 'chronos',
|
|
42
|
-
});
|
|
43
|
-
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'run_backtest',
|
|
47
|
-
description: 'Run backtest for a trading strategy on a symbol. x402:
|
|
48
|
-
schema: z.object({
|
|
49
|
-
symbol: z.string().describe('Stock symbol'),
|
|
50
|
-
startDate: z.string().nullable().default(null).describe('Start date YYYY-MM-DD'),
|
|
51
|
-
endDate: z.string().nullable().default(null).describe('End date YYYY-MM-DD'),
|
|
52
|
-
strategy: z.string().default('chronos').describe('Strategy name'),
|
|
53
|
-
}),
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const link_bank_account = tool(
|
|
58
|
-
async () => {
|
|
59
|
-
const out = await mcpClient.callTool('link_bank_account', {});
|
|
60
|
-
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: 'link_bank_account',
|
|
64
|
-
description: 'Start bank linking flow (
|
|
65
|
-
schema: z.object({}),
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const get_agent_reputation_score = tool(
|
|
70
|
-
async ({ agent_address, payer_wallet }) => {
|
|
71
|
-
const out = await mcpClient.callTool('get_agent_reputation_score', {
|
|
72
|
-
agent_address: agent_address || undefined,
|
|
73
|
-
payer_wallet: payer_wallet || undefined,
|
|
74
|
-
});
|
|
75
|
-
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: 'get_agent_reputation_score',
|
|
79
|
-
description: 'Get agent reputation score for an allowlisted wallet. Returns
|
|
80
|
-
schema: z.object({
|
|
81
|
-
agent_address: z.string().optional().describe('Wallet to query (allowlisted agent)'),
|
|
82
|
-
payer_wallet: z.string().optional().describe('When using lender credits, your registered paying wallet'),
|
|
83
|
-
}),
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const get_borrower_score = tool(
|
|
88
|
-
async ({ agent_address, payer_wallet }) => {
|
|
89
|
-
const out = await mcpClient.callTool('get_borrower_score', {
|
|
90
|
-
agent_address: agent_address || undefined,
|
|
91
|
-
payer_wallet: payer_wallet || undefined,
|
|
92
|
-
});
|
|
93
|
-
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: 'get_borrower_score',
|
|
97
|
-
description: 'Get borrower score for an allowlisted
|
|
98
|
-
schema: z.object({
|
|
99
|
-
agent_address: z.string().optional().describe('Agent wallet to get score for'),
|
|
100
|
-
payer_wallet: z.string().optional().describe('When using lender credits, your registered paying wallet'),
|
|
101
|
-
}),
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const get_agent_reputation_score_by_email = tool(
|
|
106
|
-
async ({ email, payer_wallet }) => {
|
|
107
|
-
const out = await mcpClient.callTool('get_agent_reputation_score_by_email', {
|
|
108
|
-
email: email || undefined,
|
|
109
|
-
payer_wallet: payer_wallet || undefined,
|
|
110
|
-
});
|
|
111
|
-
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: 'get_agent_reputation_score_by_email',
|
|
115
|
-
description: 'Get agent reputation score by email (resolves to allowlisted
|
|
116
|
-
schema: z.object({
|
|
117
|
-
email: z.string().describe('Email to resolve to an allowlisted agent'),
|
|
118
|
-
payer_wallet: z.string().optional().describe('When using lender credits, your registered paying wallet'),
|
|
119
|
-
}),
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
const get_borrower_score_by_email = tool(
|
|
124
|
-
async ({ email, payer_wallet }) => {
|
|
125
|
-
const out = await mcpClient.callTool('get_borrower_score_by_email', {
|
|
126
|
-
email: email || undefined,
|
|
127
|
-
payer_wallet: payer_wallet || undefined,
|
|
128
|
-
});
|
|
129
|
-
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: 'get_borrower_score_by_email',
|
|
133
|
-
description: 'Get borrower score by email (resolves to allowlisted
|
|
134
|
-
schema: z.object({
|
|
135
|
-
email: z.string().describe('Email to resolve to an allowlisted agent'),
|
|
136
|
-
payer_wallet: z.string().optional().describe('When using lender credits, your registered paying wallet'),
|
|
137
|
-
}),
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
return [
|
|
142
|
-
run_prediction,
|
|
143
|
-
run_backtest,
|
|
144
|
-
link_bank_account,
|
|
145
|
-
get_agent_reputation_score,
|
|
146
|
-
get_borrower_score,
|
|
147
|
-
get_agent_reputation_score_by_email,
|
|
148
|
-
get_borrower_score_by_email,
|
|
149
|
-
];
|
|
150
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* MCP tools as LangChain tools: run_prediction, run_backtest, link_bank_account,
|
|
3
|
+
* get_agent_reputation_score, get_borrower_score, get_agent_reputation_score_by_email, get_borrower_score_by_email.
|
|
4
|
+
* Each invokes mcpClient.callTool(name, args) with x402 retry inside the client.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { tool } from '@langchain/core/tools';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {{ callTool: (name: string, args: Object) => Promise<Object> }} mcpClient - from createMcpClient()
|
|
12
|
+
* @returns {import('@langchain/core/tools').StructuredToolInterface[]}
|
|
13
|
+
*/
|
|
14
|
+
export function createMcpTools(mcpClient) {
|
|
15
|
+
const run_prediction = tool(
|
|
16
|
+
async ({ symbol, horizon }) => {
|
|
17
|
+
console.log(`Calling run_prediction: symbol=${symbol}, horizon=${horizon}`);
|
|
18
|
+
const out = await mcpClient.callTool('run_prediction', {
|
|
19
|
+
symbol: symbol || 'AAPL',
|
|
20
|
+
horizon: horizon ?? 30,
|
|
21
|
+
});
|
|
22
|
+
console.log('MCP response:', JSON.stringify(out, null, 2));
|
|
23
|
+
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'run_prediction',
|
|
27
|
+
description: 'Run stock prediction for a ticker symbol. Returns forecast data with confidence intervals. Cost ~6c USDC via x402 (payment automatic). Prerequisite: funded + whitelisted Aptos or EVM wallet.',
|
|
28
|
+
schema: z.object({
|
|
29
|
+
symbol: z.string().describe('Stock symbol (e.g. AAPL)'),
|
|
30
|
+
horizon: z.number().default(30).describe('Prediction horizon in days'),
|
|
31
|
+
}),
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const run_backtest = tool(
|
|
36
|
+
async ({ symbol, startDate, endDate, strategy }) => {
|
|
37
|
+
const out = await mcpClient.callTool('run_backtest', {
|
|
38
|
+
symbol: symbol || 'AAPL',
|
|
39
|
+
startDate: startDate || '',
|
|
40
|
+
endDate: endDate || '',
|
|
41
|
+
strategy: strategy || 'chronos',
|
|
42
|
+
});
|
|
43
|
+
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'run_backtest',
|
|
47
|
+
description: 'Run backtest for a trading strategy on a symbol. Returns performance metrics (returns, drawdown, sharpe). Cost ~6c USDC via x402 (payment automatic). Prerequisite: funded + whitelisted Aptos or EVM wallet.',
|
|
48
|
+
schema: z.object({
|
|
49
|
+
symbol: z.string().describe('Stock symbol'),
|
|
50
|
+
startDate: z.string().nullable().default(null).describe('Start date YYYY-MM-DD'),
|
|
51
|
+
endDate: z.string().nullable().default(null).describe('End date YYYY-MM-DD'),
|
|
52
|
+
strategy: z.string().default('chronos').describe('Strategy name'),
|
|
53
|
+
}),
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const link_bank_account = tool(
|
|
58
|
+
async () => {
|
|
59
|
+
const out = await mcpClient.callTool('link_bank_account', {});
|
|
60
|
+
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'link_bank_account',
|
|
64
|
+
description: 'Start Plaid bank linking flow. Returns link_token for the user to complete bank connection. Cost ~5c via x402 (payment automatic). Prerequisite: funded + whitelisted EVM wallet (Base Sepolia for testnet).',
|
|
65
|
+
schema: z.object({}),
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const get_agent_reputation_score = tool(
|
|
70
|
+
async ({ agent_address, payer_wallet }) => {
|
|
71
|
+
const out = await mcpClient.callTool('get_agent_reputation_score', {
|
|
72
|
+
agent_address: agent_address || undefined,
|
|
73
|
+
payer_wallet: payer_wallet || undefined,
|
|
74
|
+
});
|
|
75
|
+
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'get_agent_reputation_score',
|
|
79
|
+
description: 'Get agent reputation score (ability to transact via x402) for an allowlisted wallet. Returns { reputation_score } or 403 if not allowlisted. Cost ~6c via x402, or free with lender credits (pass payer_wallet). Call get_wallet_addresses first to get the address.',
|
|
80
|
+
schema: z.object({
|
|
81
|
+
agent_address: z.string().optional().describe('Wallet to query (allowlisted agent)'),
|
|
82
|
+
payer_wallet: z.string().optional().describe('When using lender credits, your registered paying wallet'),
|
|
83
|
+
}),
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const get_borrower_score = tool(
|
|
88
|
+
async ({ agent_address, payer_wallet }) => {
|
|
89
|
+
const out = await mcpClient.callTool('get_borrower_score', {
|
|
90
|
+
agent_address: agent_address || undefined,
|
|
91
|
+
payer_wallet: payer_wallet || undefined,
|
|
92
|
+
});
|
|
93
|
+
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'get_borrower_score',
|
|
97
|
+
description: 'Get borrower score (real borrower behavior) for an allowlisted wallet. Returns { score } (100 base, higher with bank linked). Cost ~6c via x402, or free with lender credits (pass payer_wallet).',
|
|
98
|
+
schema: z.object({
|
|
99
|
+
agent_address: z.string().optional().describe('Agent wallet to get score for'),
|
|
100
|
+
payer_wallet: z.string().optional().describe('When using lender credits, your registered paying wallet'),
|
|
101
|
+
}),
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const get_agent_reputation_score_by_email = tool(
|
|
106
|
+
async ({ email, payer_wallet }) => {
|
|
107
|
+
const out = await mcpClient.callTool('get_agent_reputation_score_by_email', {
|
|
108
|
+
email: email || undefined,
|
|
109
|
+
payer_wallet: payer_wallet || undefined,
|
|
110
|
+
});
|
|
111
|
+
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'get_agent_reputation_score_by_email',
|
|
115
|
+
description: 'Get agent reputation score by email (resolves email to allowlisted wallet). Higher fee than address-based lookup. Requires SCORE_BY_EMAIL_ENABLED on server. Returns { reputation_score } or error.',
|
|
116
|
+
schema: z.object({
|
|
117
|
+
email: z.string().describe('Email to resolve to an allowlisted agent'),
|
|
118
|
+
payer_wallet: z.string().optional().describe('When using lender credits, your registered paying wallet'),
|
|
119
|
+
}),
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const get_borrower_score_by_email = tool(
|
|
124
|
+
async ({ email, payer_wallet }) => {
|
|
125
|
+
const out = await mcpClient.callTool('get_borrower_score_by_email', {
|
|
126
|
+
email: email || undefined,
|
|
127
|
+
payer_wallet: payer_wallet || undefined,
|
|
128
|
+
});
|
|
129
|
+
return typeof out?.result === 'object' ? JSON.stringify(out.result) : JSON.stringify(out);
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: 'get_borrower_score_by_email',
|
|
133
|
+
description: 'Get borrower score by email (resolves email to allowlisted wallet). Higher fee than address-based lookup. Requires SCORE_BY_EMAIL_ENABLED on server. Returns { score } or error.',
|
|
134
|
+
schema: z.object({
|
|
135
|
+
email: z.string().describe('Email to resolve to an allowlisted agent'),
|
|
136
|
+
payer_wallet: z.string().optional().describe('When using lender credits, your registered paying wallet'),
|
|
137
|
+
}),
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
return [
|
|
142
|
+
run_prediction,
|
|
143
|
+
run_backtest,
|
|
144
|
+
link_bank_account,
|
|
145
|
+
get_agent_reputation_score,
|
|
146
|
+
get_borrower_score,
|
|
147
|
+
get_agent_reputation_score_by_email,
|
|
148
|
+
get_borrower_score_by_email,
|
|
149
|
+
];
|
|
150
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -44,7 +44,7 @@ function main() {
|
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// Default: run the
|
|
47
|
+
// Default: run the skill demo (backward compatibility: npx cornerstone-autonomous-agent "some message")
|
|
48
48
|
const runAgentPath = join(root, 'src/run-agent.js');
|
|
49
49
|
const child = spawn(process.execPath, [runAgentPath, ...args], {
|
|
50
50
|
stdio: 'inherit',
|
|
@@ -28,7 +28,7 @@ export async function buildAptosPaymentPayload(paymentRequirements, wallet) {
|
|
|
28
28
|
// Aptos SDK parses payTo as address; empty string causes "Hex string is too short"
|
|
29
29
|
if (!payTo || payTo.length < 32) {
|
|
30
30
|
throw new Error(
|
|
31
|
-
'Payment requirements missing valid payTo address. Set APTOS_PAYTO_ADDRESS in server .env or register a pay_to address at
|
|
31
|
+
'Payment requirements missing valid payTo address. Set APTOS_PAYTO_ADDRESS in server .env or register a pay_to address at https://arnstein.ch/flow.html'
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -26,7 +26,7 @@ export async function getEvmPaymentPayload(paymentRequirements) {
|
|
|
26
26
|
const to = (paymentRequirements.payTo || '').trim();
|
|
27
27
|
if (!to || !to.startsWith('0x') || to.length < 40) {
|
|
28
28
|
throw new Error(
|
|
29
|
-
'Payment requirements missing valid payTo address. Set BASE_SEPOLIA_PAYTO in server .env or register a pay_to address at
|
|
29
|
+
'Payment requirements missing valid payTo address. Set BASE_SEPOLIA_PAYTO in server .env or register a pay_to address at https://arnstein.ch/flow.html'
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
const value = BigInt(
|
package/src/lib/mcp/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MCP client with x402 retry: uses official MCP SDK
|
|
2
|
+
* MCP client with x402 retry: uses official MCP SDK.
|
|
3
|
+
* Tries StreamableHTTP transport first; falls back to SSE if the server returns 405.
|
|
3
4
|
* On 402 from tool call, pays via facilitator and retries in one shot (agent calls
|
|
4
5
|
* the tool once; 402 + verify + settle + retry happen inside callTool; agent gets
|
|
5
6
|
* final result or error, never 402).
|
|
@@ -7,6 +8,7 @@
|
|
|
7
8
|
|
|
8
9
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
9
10
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
11
|
+
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
10
12
|
import { verifyPayment, settlePayment } from '../x402/index.js';
|
|
11
13
|
|
|
12
14
|
/** Max time for a single callTool (connect + call + payment flow + retry); ms. MCP responses (e.g. prediction) can take > 1 min. */
|
|
@@ -21,9 +23,9 @@ function withTimeout(promise, ms, label) {
|
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* @param {Object} config
|
|
24
|
-
* @param {string} config.baseUrl - MCP server base URL (e.g.
|
|
26
|
+
* @param {string} config.baseUrl - MCP server base URL (e.g. https://arnstein.ch); client appends /mcp
|
|
25
27
|
* @param {string} config.facilitatorUrl - x402 facilitator base URL (Aptos)
|
|
26
|
-
* @param {string} [config.evmFacilitatorUrl] - facilitator for EVM (open_bank_account); defaults to facilitatorUrl
|
|
28
|
+
* @param {string} [config.evmFacilitatorUrl] - facilitator for EVM (open_bank_account); defaults to facilitatorUrl
|
|
27
29
|
* @param {(r: import('../x402/types.js').PaymentRequirements) => Promise<Object>} config.getAptosPaymentPayload
|
|
28
30
|
* @param {(r: import('../x402/types.js').PaymentRequirements) => Promise<Object>} config.getEvmPaymentPayload
|
|
29
31
|
* @param {number} [config.maxRetries]
|
|
@@ -43,7 +45,7 @@ export function createMcpClient(config) {
|
|
|
43
45
|
let isConnected = false;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Connect to MCP server
|
|
48
|
+
* Connect to MCP server (StreamableHTTP first, SSE fallback)
|
|
47
49
|
*/
|
|
48
50
|
async function connect() {
|
|
49
51
|
if (isConnected && mcpClient) {
|
|
@@ -51,24 +53,40 @@ export function createMcpClient(config) {
|
|
|
51
53
|
return;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const transport = new StreamableHTTPClientTransport(
|
|
57
|
-
new URL(mcpUrl)
|
|
58
|
-
);
|
|
56
|
+
const clientInfo = { name: 'cornerstone-agent', version: '1.0.0' };
|
|
57
|
+
const clientOpts = { capabilities: {} };
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
// Try StreamableHTTP first
|
|
60
|
+
console.log(`Connecting to MCP server at ${mcpUrl} (StreamableHTTP)...`);
|
|
61
|
+
try {
|
|
62
|
+
const transport = new StreamableHTTPClientTransport(new URL(mcpUrl));
|
|
63
|
+
mcpClient = new Client(clientInfo, clientOpts);
|
|
64
|
+
await mcpClient.connect(transport);
|
|
65
|
+
isConnected = true;
|
|
66
|
+
console.log('Connected to MCP server via StreamableHTTP');
|
|
67
|
+
return;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
// 405 = server doesn't support StreamableHTTP, try SSE
|
|
70
|
+
if (error.code === 405 || error.message?.includes('405') || error.message?.includes('Method Not Allowed')) {
|
|
71
|
+
console.log('StreamableHTTP not supported, trying SSE transport...');
|
|
72
|
+
mcpClient = null;
|
|
73
|
+
} else {
|
|
74
|
+
console.error('Failed to connect to MCP server:', error);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
66
78
|
|
|
79
|
+
// Fallback: SSE transport (uses /sse endpoint by convention)
|
|
80
|
+
const sseUrl = `${baseUrl}/sse`;
|
|
81
|
+
console.log(`Connecting to MCP server at ${sseUrl} (SSE)...`);
|
|
82
|
+
try {
|
|
83
|
+
const transport = new SSEClientTransport(new URL(sseUrl));
|
|
84
|
+
mcpClient = new Client(clientInfo, clientOpts);
|
|
67
85
|
await mcpClient.connect(transport);
|
|
68
86
|
isConnected = true;
|
|
69
|
-
console.log('
|
|
87
|
+
console.log('Connected to MCP server via SSE');
|
|
70
88
|
} catch (error) {
|
|
71
|
-
console.error('Failed to connect to MCP server:', error);
|
|
89
|
+
console.error('Failed to connect to MCP server (SSE):', error);
|
|
72
90
|
throw error;
|
|
73
91
|
}
|
|
74
92
|
}
|
package/src/run-agent.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Entrypoint for the
|
|
3
|
+
* Entrypoint for the skill demo (x402 MCP + LangChain.js runner).
|
|
4
4
|
* Usage: node src/run-agent.js [message]
|
|
5
5
|
* If no message, runs demo prompt.
|
|
6
6
|
*/
|
|
@@ -17,7 +17,7 @@ const DEMO_PROMPT =
|
|
|
17
17
|
async function main() {
|
|
18
18
|
const message = process.argv.slice(2).join(' ').trim() || DEMO_PROMPT;
|
|
19
19
|
|
|
20
|
-
const mcpServerUrl = process.env.MCP_SERVER_URL || '
|
|
20
|
+
const mcpServerUrl = process.env.MCP_SERVER_URL || 'https://arnstein.ch';
|
|
21
21
|
const defaultFacilitator = 'https://x402-navy.vercel.app/facilitator';
|
|
22
22
|
let facilitatorUrl = process.env.X402_FACILITATOR_URL || defaultFacilitator;
|
|
23
23
|
if (facilitatorUrl.includes('facilitator.x402.org')) {
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Print all agent wallet addresses for whitelisting during a demo.
|
|
4
|
-
* Run from agent project: node src/show-agent-addresses.js (or npm run addresses).
|
|
5
|
-
* Package: https://github.com/FinTechTonic/autonomous-agent
|
|
6
|
-
* Then add each address at
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { getAllWalletInfos as getAptosAll, exists as aptosExists } from './lib/aptos/wallet.js';
|
|
10
|
-
import { getAllWalletInfos as getEvmAll, exists as evmExists } from './lib/wallet.js';
|
|
11
|
-
|
|
12
|
-
const aptosList = aptosExists() ? getAptosAll() : [];
|
|
13
|
-
const evmList = evmExists() ? getEvmAll() : [];
|
|
14
|
-
|
|
15
|
-
console.log('\nAgent wallet addresses (whitelist these at
|
|
16
|
-
console.log(' Add multiple EVM and Aptos rows as needed; optionally tag each as testnet or mainnet.\n');
|
|
17
|
-
if (aptosList.length) {
|
|
18
|
-
aptosList.forEach((w, i) => {
|
|
19
|
-
const net = w.network ? ` [${w.network}]` : '';
|
|
20
|
-
console.log(` Aptos (run_prediction, run_backtest)${net}: ${w.address}`);
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
console.log(' Aptos: none. Run: node src/setup-aptos.js or create_aptos_wallet (optionally network: "testnet"|"mainnet").');
|
|
24
|
-
}
|
|
25
|
-
if (evmList.length) {
|
|
26
|
-
evmList.forEach((w, i) => {
|
|
27
|
-
const net = w.network ? ` [${w.network}]` : '';
|
|
28
|
-
console.log(` EVM (link_bank_account)${net}: ${w.address}`);
|
|
29
|
-
});
|
|
30
|
-
} else {
|
|
31
|
-
console.log(' EVM: none. Run: node src/setup.js or create_evm_wallet (optionally network: "testnet"|"mainnet"); or set EVM_PRIVATE_KEY.');
|
|
32
|
-
}
|
|
33
|
-
console.log('');
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Print all agent wallet addresses for whitelisting during a demo.
|
|
4
|
+
* Run from agent project: node src/show-agent-addresses.js (or npm run addresses).
|
|
5
|
+
* Package: https://github.com/FinTechTonic/autonomous-agent
|
|
6
|
+
* Then add each address at https://arnstein.ch/flow.html (EVM and Aptos rows; optional testnet/mainnet tag).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getAllWalletInfos as getAptosAll, exists as aptosExists } from './lib/aptos/wallet.js';
|
|
10
|
+
import { getAllWalletInfos as getEvmAll, exists as evmExists } from './lib/wallet.js';
|
|
11
|
+
|
|
12
|
+
const aptosList = aptosExists() ? getAptosAll() : [];
|
|
13
|
+
const evmList = evmExists() ? getEvmAll() : [];
|
|
14
|
+
|
|
15
|
+
console.log('\nAgent wallet addresses (whitelist these at https://arnstein.ch/flow.html):');
|
|
16
|
+
console.log(' Add multiple EVM and Aptos rows as needed; optionally tag each as testnet or mainnet.\n');
|
|
17
|
+
if (aptosList.length) {
|
|
18
|
+
aptosList.forEach((w, i) => {
|
|
19
|
+
const net = w.network ? ` [${w.network}]` : '';
|
|
20
|
+
console.log(` Aptos (run_prediction, run_backtest)${net}: ${w.address}`);
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
console.log(' Aptos: none. Run: node src/setup-aptos.js or create_aptos_wallet (optionally network: "testnet"|"mainnet").');
|
|
24
|
+
}
|
|
25
|
+
if (evmList.length) {
|
|
26
|
+
evmList.forEach((w, i) => {
|
|
27
|
+
const net = w.network ? ` [${w.network}]` : '';
|
|
28
|
+
console.log(` EVM (link_bank_account)${net}: ${w.address}`);
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
console.log(' EVM: none. Run: node src/setup.js or create_evm_wallet (optionally network: "testnet"|"mainnet"); or set EVM_PRIVATE_KEY.');
|
|
32
|
+
}
|
|
33
|
+
console.log('');
|