cache-overflow-mcp 0.3.6 → 0.3.8
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 +28 -76
- package/dist/client.d.ts +5 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +157 -9
- package/dist/client.js.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/prompts/index.d.ts +6 -0
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +55 -1
- package/dist/prompts/index.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +18 -10
- package/dist/server.js.map +1 -1
- package/dist/services/config-service.d.ts +27 -0
- package/dist/services/config-service.d.ts.map +1 -0
- package/dist/services/config-service.js +100 -0
- package/dist/services/config-service.js.map +1 -0
- package/dist/testing/mock-server.d.ts.map +1 -1
- package/dist/testing/mock-server.js +13 -5
- package/dist/testing/mock-server.js.map +1 -1
- package/dist/tools/find-solution.d.ts.map +1 -1
- package/dist/tools/find-solution.js +74 -3
- package/dist/tools/find-solution.js.map +1 -1
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +53 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/publish-solution.d.ts.map +1 -1
- package/dist/tools/publish-solution.js +68 -3
- package/dist/tools/publish-solution.js.map +1 -1
- package/dist/tools/submit-feedback.d.ts.map +1 -1
- package/dist/tools/submit-feedback.js +62 -2
- package/dist/tools/submit-feedback.js.map +1 -1
- package/dist/tools/submit-verification.d.ts.map +1 -1
- package/dist/tools/submit-verification.js +62 -2
- package/dist/tools/submit-verification.js.map +1 -1
- package/dist/tools/unlock-solution.d.ts.map +1 -1
- package/dist/tools/unlock-solution.js +57 -2
- package/dist/tools/unlock-solution.js.map +1 -1
- package/dist/types.d.ts +38 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/verification-dialog.d.ts +1 -1
- package/dist/ui/verification-dialog.d.ts.map +1 -1
- package/dist/ui/verification-dialog.js +78 -4
- package/dist/ui/verification-dialog.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +177 -9
- package/src/config.ts +1 -1
- package/src/prompts/index.ts +67 -1
- package/src/server.ts +37 -19
- package/src/services/config-service.ts +119 -0
- package/src/testing/mock-server.ts +15 -7
- package/src/tools/find-solution.ts +75 -3
- package/src/tools/index.ts +70 -1
- package/src/tools/publish-solution.ts +71 -3
- package/src/tools/submit-feedback.ts +62 -2
- package/src/tools/submit-verification.ts +62 -2
- package/src/tools/unlock-solution.ts +56 -2
- package/src/types.ts +48 -0
- package/src/ui/verification-dialog.ts +84 -4
- package/E2E-TESTING.md +0 -195
- package/TROUBLESHOOTING.md +0 -219
- package/scripts/mock-server.js +0 -37
- package/scripts/view-logs.js +0 -125
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { ToolDefinition } from './index.js';
|
|
2
2
|
import { showVerificationDialog } from '../ui/verification-dialog.js';
|
|
3
|
+
import { config } from '../config.js';
|
|
4
|
+
|
|
5
|
+
// #6 - Improve error messages with context
|
|
6
|
+
function getErrorTitle(error: string): string {
|
|
7
|
+
if (error.includes('timeout') || error.includes('timed out')) return 'Request Timed Out';
|
|
8
|
+
if (error.includes('network') || error.includes('fetch')) return 'Network Connection Failed';
|
|
9
|
+
if (error.includes('balance') || error.includes('insufficient')) return 'Insufficient Token Balance';
|
|
10
|
+
if (error.includes('auth') || error.includes('Authentication')) return 'Authentication Failed';
|
|
11
|
+
if (error.includes('Rate limit')) return 'Rate Limit Exceeded';
|
|
12
|
+
return 'Operation Failed';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getRecoverySuggestions(error: string): string {
|
|
16
|
+
if (error.includes('timeout') || error.includes('timed out')) {
|
|
17
|
+
return '- Check your internet connection\n- Try again in a moment\n- The server may be experiencing high load';
|
|
18
|
+
}
|
|
19
|
+
if (error.includes('balance') || error.includes('insufficient')) {
|
|
20
|
+
return '- Check your balance with another tool or API call\n- Earn tokens by publishing solutions\n- Look for solutions with human_verification_required=false';
|
|
21
|
+
}
|
|
22
|
+
if (error.includes('auth') || error.includes('Authentication')) {
|
|
23
|
+
return '- Verify your CACHE_OVERFLOW_TOKEN environment variable is set correctly\n- Token should start with "co_"\n- Check if your token has expired';
|
|
24
|
+
}
|
|
25
|
+
if (error.includes('Rate limit')) {
|
|
26
|
+
return '- Wait the specified time before retrying\n- Consider using solutions with human_verification_required=false to avoid token costs';
|
|
27
|
+
}
|
|
28
|
+
if (error.includes('network') || error.includes('fetch')) {
|
|
29
|
+
return '- Check your internet connection\n- Verify the CACHE_OVERFLOW_URL is correct\n- Try again in a moment';
|
|
30
|
+
}
|
|
31
|
+
return '- Check the log file for details\n- Verify your CACHE_OVERFLOW_TOKEN is valid\n- Try again in a moment';
|
|
32
|
+
}
|
|
3
33
|
|
|
4
34
|
export const findSolution: ToolDefinition = {
|
|
5
35
|
definition: {
|
|
@@ -18,12 +48,44 @@ export const findSolution: ToolDefinition = {
|
|
|
18
48
|
},
|
|
19
49
|
},
|
|
20
50
|
handler: async (args, client) => {
|
|
21
|
-
|
|
51
|
+
// #5 - Add input validation
|
|
52
|
+
const query = (args.query as string || '').trim();
|
|
53
|
+
|
|
54
|
+
if (!query) {
|
|
55
|
+
return {
|
|
56
|
+
content: [{ type: 'text', text: 'Error: Query cannot be empty. Please provide a description of the problem you are trying to solve.' }],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (query.length < 5) {
|
|
61
|
+
return {
|
|
62
|
+
content: [{ type: 'text', text: 'Error: Query must be at least 5 characters long. Please provide more details about the problem.' }],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (query.length > 500) {
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: 'text', text: 'Error: Query must be less than 500 characters. Please provide a more concise description.' }],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
22
72
|
const result = await client.findSolution(query);
|
|
23
73
|
|
|
24
74
|
if (!result.success) {
|
|
75
|
+
// #6 - Improve error messages with context
|
|
76
|
+
const errorMessage = [
|
|
77
|
+
`❌ ${getErrorTitle(result.error || '')}`,
|
|
78
|
+
'',
|
|
79
|
+
result.error,
|
|
80
|
+
'',
|
|
81
|
+
'💡 **What to try:**',
|
|
82
|
+
getRecoverySuggestions(result.error || ''),
|
|
83
|
+
'',
|
|
84
|
+
`📋 **Logs**: Check ${config.logging.logDir || '~/.cache-overflow'}/cache-overflow-mcp.log for details`,
|
|
85
|
+
].join('\n');
|
|
86
|
+
|
|
25
87
|
return {
|
|
26
|
-
content: [{ type: 'text', text:
|
|
88
|
+
content: [{ type: 'text', text: errorMessage }],
|
|
27
89
|
};
|
|
28
90
|
}
|
|
29
91
|
|
|
@@ -37,7 +99,17 @@ export const findSolution: ToolDefinition = {
|
|
|
37
99
|
|
|
38
100
|
// If user made a choice (not cancelled), submit verification
|
|
39
101
|
if (verificationResult !== null) {
|
|
40
|
-
|
|
102
|
+
// #10 - Catch verification submission errors
|
|
103
|
+
try {
|
|
104
|
+
const submitResult = await client.submitVerification(solution.solution_id, verificationResult);
|
|
105
|
+
if (!submitResult.success) {
|
|
106
|
+
// Log but don't fail - user still gets the solution content
|
|
107
|
+
console.warn(`Warning: Failed to submit verification for solution ${solution.solution_id}: ${submitResult.error}`);
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
// Log but don't fail - user still gets the solution content
|
|
111
|
+
console.warn(`Warning: Error submitting verification for solution ${solution.solution_id}:`, error);
|
|
112
|
+
}
|
|
41
113
|
}
|
|
42
114
|
}
|
|
43
115
|
}
|
package/src/tools/index.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
import { CacheOverflowClient } from '../client.js';
|
|
3
|
+
import { configService } from '../services/config-service.js';
|
|
4
|
+
import { logger } from '../logger.js';
|
|
5
|
+
import type { RemoteToolDefinition } from '../types.js';
|
|
3
6
|
import { findSolution } from './find-solution.js';
|
|
4
7
|
import { unlockSolution } from './unlock-solution.js';
|
|
5
8
|
import { publishSolution } from './publish-solution.js';
|
|
@@ -14,10 +17,76 @@ export interface ToolDefinition {
|
|
|
14
17
|
) => Promise<{ content: Array<{ type: string; text: string }> }>;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
// Map of tool handlers by name
|
|
21
|
+
const toolHandlers: Record<
|
|
22
|
+
string,
|
|
23
|
+
(
|
|
24
|
+
args: Record<string, unknown>,
|
|
25
|
+
client: CacheOverflowClient
|
|
26
|
+
) => Promise<{ content: Array<{ type: string; text: string }> }>
|
|
27
|
+
> = {
|
|
28
|
+
find_solution: findSolution.handler,
|
|
29
|
+
unlock_solution: unlockSolution.handler,
|
|
30
|
+
publish_solution: publishSolution.handler,
|
|
31
|
+
submit_verification: submitVerification.handler,
|
|
32
|
+
submit_feedback: submitFeedback.handler,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Fallback tools used when backend is unavailable
|
|
36
|
+
export const FALLBACK_TOOLS: ToolDefinition[] = [
|
|
18
37
|
findSolution,
|
|
19
38
|
unlockSolution,
|
|
20
39
|
publishSolution,
|
|
21
40
|
submitVerification,
|
|
22
41
|
submitFeedback,
|
|
23
42
|
];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Convert a remote tool definition to a local Tool format
|
|
46
|
+
*/
|
|
47
|
+
function remoteToLocalTool(remote: RemoteToolDefinition): Tool {
|
|
48
|
+
return {
|
|
49
|
+
name: remote.name,
|
|
50
|
+
description: remote.description,
|
|
51
|
+
inputSchema: {
|
|
52
|
+
type: remote.inputSchema.type as 'object',
|
|
53
|
+
properties: remote.inputSchema.properties,
|
|
54
|
+
required: remote.inputSchema.required,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get tools with definitions from the backend API.
|
|
61
|
+
* Falls back to hardcoded definitions if the backend is unavailable.
|
|
62
|
+
*/
|
|
63
|
+
export async function getTools(): Promise<ToolDefinition[]> {
|
|
64
|
+
const remoteConfig = await configService.fetchConfig();
|
|
65
|
+
|
|
66
|
+
if (!remoteConfig) {
|
|
67
|
+
logger.info('Using fallback tool definitions');
|
|
68
|
+
return FALLBACK_TOOLS;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const tools: ToolDefinition[] = [];
|
|
72
|
+
|
|
73
|
+
for (const remoteTool of remoteConfig.tools) {
|
|
74
|
+
const handler = toolHandlers[remoteTool.name];
|
|
75
|
+
|
|
76
|
+
if (!handler) {
|
|
77
|
+
// Skip tools without handlers (allows backend to prepare for future tools)
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
tools.push({
|
|
82
|
+
definition: remoteToLocalTool(remoteTool),
|
|
83
|
+
handler,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return tools;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Keep backward compatibility - export tools array for existing code
|
|
91
|
+
// Note: This is the fallback, prefer using getTools() for dynamic loading
|
|
92
|
+
export const tools: ToolDefinition[] = FALLBACK_TOOLS;
|
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
import { ToolDefinition } from './index.js';
|
|
2
|
+
import { config } from '../config.js';
|
|
3
|
+
|
|
4
|
+
// #6 - Improve error messages with context
|
|
5
|
+
function getErrorTitle(error: string): string {
|
|
6
|
+
if (error.includes('timeout') || error.includes('timed out')) return 'Request Timed Out';
|
|
7
|
+
if (error.includes('network') || error.includes('fetch')) return 'Network Connection Failed';
|
|
8
|
+
if (error.includes('auth') || error.includes('Authentication')) return 'Authentication Failed';
|
|
9
|
+
if (error.includes('Rate limit')) return 'Rate Limit Exceeded';
|
|
10
|
+
if (error.includes('duplicate') || error.includes('already exists')) return 'Duplicate Solution';
|
|
11
|
+
return 'Operation Failed';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getRecoverySuggestions(error: string): string {
|
|
15
|
+
if (error.includes('timeout') || error.includes('timed out')) {
|
|
16
|
+
return '- Check your internet connection\n- Try again in a moment\n- The server may be experiencing high load';
|
|
17
|
+
}
|
|
18
|
+
if (error.includes('auth') || error.includes('Authentication')) {
|
|
19
|
+
return '- Verify your CACHE_OVERFLOW_TOKEN environment variable is set correctly\n- Token should start with "co_"\n- Check if your token has expired';
|
|
20
|
+
}
|
|
21
|
+
if (error.includes('Rate limit')) {
|
|
22
|
+
return '- Wait the specified time before retrying';
|
|
23
|
+
}
|
|
24
|
+
if (error.includes('duplicate') || error.includes('already exists')) {
|
|
25
|
+
return '- A similar solution may already exist\n- Try searching first with find_solution\n- Consider adding more specific details to your solution';
|
|
26
|
+
}
|
|
27
|
+
if (error.includes('network') || error.includes('fetch')) {
|
|
28
|
+
return '- Check your internet connection\n- Verify the CACHE_OVERFLOW_URL is correct\n- Try again in a moment';
|
|
29
|
+
}
|
|
30
|
+
return '- Check the log file for details\n- Verify your CACHE_OVERFLOW_TOKEN is valid\n- Try again in a moment';
|
|
31
|
+
}
|
|
2
32
|
|
|
3
33
|
export const publishSolution: ToolDefinition = {
|
|
4
34
|
definition: {
|
|
@@ -21,13 +51,51 @@ export const publishSolution: ToolDefinition = {
|
|
|
21
51
|
},
|
|
22
52
|
},
|
|
23
53
|
handler: async (args, client) => {
|
|
24
|
-
|
|
25
|
-
const
|
|
54
|
+
// #5 - Add input validation
|
|
55
|
+
const queryTitle = (args.query_title as string || '').trim();
|
|
56
|
+
const solutionBody = (args.solution_body as string || '').trim();
|
|
57
|
+
|
|
58
|
+
if (!queryTitle || queryTitle.length < 5) {
|
|
59
|
+
return {
|
|
60
|
+
content: [{ type: 'text', text: 'Error: Title must be at least 5 characters. Please provide a clear, descriptive title.' }],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (queryTitle.length > 200) {
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: 'text', text: 'Error: Title must be less than 200 characters. Please use a more concise title.' }],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!solutionBody || solutionBody.length < 10) {
|
|
71
|
+
return {
|
|
72
|
+
content: [{ type: 'text', text: 'Error: Solution body must be at least 10 characters. Please provide a detailed solution with Problem, Root Cause, Solution, and Verification sections.' }],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (solutionBody.length > 50000) {
|
|
77
|
+
return {
|
|
78
|
+
content: [{ type: 'text', text: 'Error: Solution body must be less than 50,000 characters. Please be more concise.' }],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
26
82
|
const result = await client.publishSolution(queryTitle, solutionBody);
|
|
27
83
|
|
|
28
84
|
if (!result.success) {
|
|
85
|
+
// #6 - Improve error messages with context
|
|
86
|
+
const errorMessage = [
|
|
87
|
+
`❌ ${getErrorTitle(result.error || '')}`,
|
|
88
|
+
'',
|
|
89
|
+
result.error,
|
|
90
|
+
'',
|
|
91
|
+
'💡 **What to try:**',
|
|
92
|
+
getRecoverySuggestions(result.error || ''),
|
|
93
|
+
'',
|
|
94
|
+
`📋 **Logs**: Check ${config.logging.logDir || '~/.cache-overflow'}/cache-overflow-mcp.log for details`,
|
|
95
|
+
].join('\n');
|
|
96
|
+
|
|
29
97
|
return {
|
|
30
|
-
content: [{ type: 'text', text:
|
|
98
|
+
content: [{ type: 'text', text: errorMessage }],
|
|
31
99
|
};
|
|
32
100
|
}
|
|
33
101
|
|
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
import { ToolDefinition } from './index.js';
|
|
2
|
+
import { config } from '../config.js';
|
|
3
|
+
|
|
4
|
+
// #6 - Improve error messages with context
|
|
5
|
+
function getErrorTitle(error: string): string {
|
|
6
|
+
if (error.includes('timeout') || error.includes('timed out')) return 'Request Timed Out';
|
|
7
|
+
if (error.includes('network') || error.includes('fetch')) return 'Network Connection Failed';
|
|
8
|
+
if (error.includes('auth') || error.includes('Authentication')) return 'Authentication Failed';
|
|
9
|
+
if (error.includes('Rate limit')) return 'Rate Limit Exceeded';
|
|
10
|
+
if (error.includes('not found') || error.includes('404')) return 'Solution Not Found';
|
|
11
|
+
if (error.includes('already submitted')) return 'Feedback Already Submitted';
|
|
12
|
+
return 'Operation Failed';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getRecoverySuggestions(error: string): string {
|
|
16
|
+
if (error.includes('timeout') || error.includes('timed out')) {
|
|
17
|
+
return '- Check your internet connection\n- Try again in a moment\n- The server may be experiencing high load';
|
|
18
|
+
}
|
|
19
|
+
if (error.includes('auth') || error.includes('Authentication')) {
|
|
20
|
+
return '- Verify your CACHE_OVERFLOW_TOKEN environment variable is set correctly\n- Token should start with "co_"\n- Check if your token has expired';
|
|
21
|
+
}
|
|
22
|
+
if (error.includes('Rate limit')) {
|
|
23
|
+
return '- Wait the specified time before retrying';
|
|
24
|
+
}
|
|
25
|
+
if (error.includes('not found') || error.includes('404')) {
|
|
26
|
+
return '- Verify the solution_id is correct\n- The solution may have been deleted';
|
|
27
|
+
}
|
|
28
|
+
if (error.includes('already submitted')) {
|
|
29
|
+
return '- You have already submitted feedback for this solution\n- No action needed';
|
|
30
|
+
}
|
|
31
|
+
if (error.includes('network') || error.includes('fetch')) {
|
|
32
|
+
return '- Check your internet connection\n- Verify the CACHE_OVERFLOW_URL is correct\n- Try again in a moment';
|
|
33
|
+
}
|
|
34
|
+
return '- Check the log file for details\n- Verify your CACHE_OVERFLOW_TOKEN is valid\n- Try again in a moment';
|
|
35
|
+
}
|
|
2
36
|
|
|
3
37
|
export const submitFeedback: ToolDefinition = {
|
|
4
38
|
definition: {
|
|
@@ -21,13 +55,39 @@ export const submitFeedback: ToolDefinition = {
|
|
|
21
55
|
},
|
|
22
56
|
},
|
|
23
57
|
handler: async (args, client) => {
|
|
24
|
-
|
|
58
|
+
// #5 - Add input validation
|
|
59
|
+
const solutionId = (args.solution_id as string || '').trim();
|
|
25
60
|
const isUseful = args.is_useful as boolean;
|
|
61
|
+
|
|
62
|
+
if (!solutionId) {
|
|
63
|
+
return {
|
|
64
|
+
content: [{ type: 'text', text: 'Error: solution_id cannot be empty. Please provide a valid solution ID.' }],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof isUseful !== 'boolean') {
|
|
69
|
+
return {
|
|
70
|
+
content: [{ type: 'text', text: 'Error: is_useful must be a boolean (true or false).' }],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
26
74
|
const result = await client.submitFeedback(solutionId, isUseful);
|
|
27
75
|
|
|
28
76
|
if (!result.success) {
|
|
77
|
+
// #6 - Improve error messages with context
|
|
78
|
+
const errorMessage = [
|
|
79
|
+
`❌ ${getErrorTitle(result.error || '')}`,
|
|
80
|
+
'',
|
|
81
|
+
result.error,
|
|
82
|
+
'',
|
|
83
|
+
'💡 **What to try:**',
|
|
84
|
+
getRecoverySuggestions(result.error || ''),
|
|
85
|
+
'',
|
|
86
|
+
`📋 **Logs**: Check ${config.logging.logDir || '~/.cache-overflow'}/cache-overflow-mcp.log for details`,
|
|
87
|
+
].join('\n');
|
|
88
|
+
|
|
29
89
|
return {
|
|
30
|
-
content: [{ type: 'text', text:
|
|
90
|
+
content: [{ type: 'text', text: errorMessage }],
|
|
31
91
|
};
|
|
32
92
|
}
|
|
33
93
|
|
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
import { ToolDefinition } from './index.js';
|
|
2
|
+
import { config } from '../config.js';
|
|
3
|
+
|
|
4
|
+
// #6 - Improve error messages with context
|
|
5
|
+
function getErrorTitle(error: string): string {
|
|
6
|
+
if (error.includes('timeout') || error.includes('timed out')) return 'Request Timed Out';
|
|
7
|
+
if (error.includes('network') || error.includes('fetch')) return 'Network Connection Failed';
|
|
8
|
+
if (error.includes('auth') || error.includes('Authentication')) return 'Authentication Failed';
|
|
9
|
+
if (error.includes('Rate limit')) return 'Rate Limit Exceeded';
|
|
10
|
+
if (error.includes('not found') || error.includes('404')) return 'Solution Not Found';
|
|
11
|
+
if (error.includes('already verified')) return 'Already Verified';
|
|
12
|
+
return 'Operation Failed';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getRecoverySuggestions(error: string): string {
|
|
16
|
+
if (error.includes('timeout') || error.includes('timed out')) {
|
|
17
|
+
return '- Check your internet connection\n- Try again in a moment\n- The server may be experiencing high load';
|
|
18
|
+
}
|
|
19
|
+
if (error.includes('auth') || error.includes('Authentication')) {
|
|
20
|
+
return '- Verify your CACHE_OVERFLOW_TOKEN environment variable is set correctly\n- Token should start with "co_"\n- Check if your token has expired';
|
|
21
|
+
}
|
|
22
|
+
if (error.includes('Rate limit')) {
|
|
23
|
+
return '- Wait the specified time before retrying';
|
|
24
|
+
}
|
|
25
|
+
if (error.includes('not found') || error.includes('404')) {
|
|
26
|
+
return '- Verify the solution_id is correct\n- The solution may have been deleted';
|
|
27
|
+
}
|
|
28
|
+
if (error.includes('already verified')) {
|
|
29
|
+
return '- You have already verified this solution\n- No action needed';
|
|
30
|
+
}
|
|
31
|
+
if (error.includes('network') || error.includes('fetch')) {
|
|
32
|
+
return '- Check your internet connection\n- Verify the CACHE_OVERFLOW_URL is correct\n- Try again in a moment';
|
|
33
|
+
}
|
|
34
|
+
return '- Check the log file for details\n- Verify your CACHE_OVERFLOW_TOKEN is valid\n- Try again in a moment';
|
|
35
|
+
}
|
|
2
36
|
|
|
3
37
|
export const submitVerification: ToolDefinition = {
|
|
4
38
|
definition: {
|
|
@@ -21,13 +55,39 @@ export const submitVerification: ToolDefinition = {
|
|
|
21
55
|
},
|
|
22
56
|
},
|
|
23
57
|
handler: async (args, client) => {
|
|
24
|
-
|
|
58
|
+
// #5 - Add input validation
|
|
59
|
+
const solutionId = (args.solution_id as string || '').trim();
|
|
25
60
|
const isSafe = args.is_safe as boolean;
|
|
61
|
+
|
|
62
|
+
if (!solutionId) {
|
|
63
|
+
return {
|
|
64
|
+
content: [{ type: 'text', text: 'Error: solution_id cannot be empty. Please provide a valid solution ID.' }],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof isSafe !== 'boolean') {
|
|
69
|
+
return {
|
|
70
|
+
content: [{ type: 'text', text: 'Error: is_safe must be a boolean (true or false).' }],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
26
74
|
const result = await client.submitVerification(solutionId, isSafe);
|
|
27
75
|
|
|
28
76
|
if (!result.success) {
|
|
77
|
+
// #6 - Improve error messages with context
|
|
78
|
+
const errorMessage = [
|
|
79
|
+
`❌ ${getErrorTitle(result.error || '')}`,
|
|
80
|
+
'',
|
|
81
|
+
result.error,
|
|
82
|
+
'',
|
|
83
|
+
'💡 **What to try:**',
|
|
84
|
+
getRecoverySuggestions(result.error || ''),
|
|
85
|
+
'',
|
|
86
|
+
`📋 **Logs**: Check ${config.logging.logDir || '~/.cache-overflow'}/cache-overflow-mcp.log for details`,
|
|
87
|
+
].join('\n');
|
|
88
|
+
|
|
29
89
|
return {
|
|
30
|
-
content: [{ type: 'text', text:
|
|
90
|
+
content: [{ type: 'text', text: errorMessage }],
|
|
31
91
|
};
|
|
32
92
|
}
|
|
33
93
|
|
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
import { ToolDefinition } from './index.js';
|
|
2
|
+
import { config } from '../config.js';
|
|
3
|
+
|
|
4
|
+
// #6 - Improve error messages with context
|
|
5
|
+
function getErrorTitle(error: string): string {
|
|
6
|
+
if (error.includes('timeout') || error.includes('timed out')) return 'Request Timed Out';
|
|
7
|
+
if (error.includes('network') || error.includes('fetch')) return 'Network Connection Failed';
|
|
8
|
+
if (error.includes('balance') || error.includes('insufficient')) return 'Insufficient Token Balance';
|
|
9
|
+
if (error.includes('auth') || error.includes('Authentication')) return 'Authentication Failed';
|
|
10
|
+
if (error.includes('Rate limit')) return 'Rate Limit Exceeded';
|
|
11
|
+
if (error.includes('not found') || error.includes('404')) return 'Solution Not Found';
|
|
12
|
+
return 'Operation Failed';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getRecoverySuggestions(error: string): string {
|
|
16
|
+
if (error.includes('timeout') || error.includes('timed out')) {
|
|
17
|
+
return '- Check your internet connection\n- Try again in a moment\n- The server may be experiencing high load';
|
|
18
|
+
}
|
|
19
|
+
if (error.includes('balance') || error.includes('insufficient')) {
|
|
20
|
+
return '- Check your balance with another tool or API call\n- Earn tokens by publishing solutions\n- Look for solutions with human_verification_required=false';
|
|
21
|
+
}
|
|
22
|
+
if (error.includes('auth') || error.includes('Authentication')) {
|
|
23
|
+
return '- Verify your CACHE_OVERFLOW_TOKEN environment variable is set correctly\n- Token should start with "co_"\n- Check if your token has expired';
|
|
24
|
+
}
|
|
25
|
+
if (error.includes('Rate limit')) {
|
|
26
|
+
return '- Wait the specified time before retrying\n- Consider using solutions with human_verification_required=false to avoid token costs';
|
|
27
|
+
}
|
|
28
|
+
if (error.includes('not found') || error.includes('404')) {
|
|
29
|
+
return '- Verify the solution_id is correct\n- The solution may have been deleted\n- Try searching again with find_solution';
|
|
30
|
+
}
|
|
31
|
+
if (error.includes('network') || error.includes('fetch')) {
|
|
32
|
+
return '- Check your internet connection\n- Verify the CACHE_OVERFLOW_URL is correct\n- Try again in a moment';
|
|
33
|
+
}
|
|
34
|
+
return '- Check the log file for details\n- Verify your CACHE_OVERFLOW_TOKEN is valid\n- Try again in a moment';
|
|
35
|
+
}
|
|
2
36
|
|
|
3
37
|
export const unlockSolution: ToolDefinition = {
|
|
4
38
|
definition: {
|
|
@@ -17,12 +51,32 @@ export const unlockSolution: ToolDefinition = {
|
|
|
17
51
|
},
|
|
18
52
|
},
|
|
19
53
|
handler: async (args, client) => {
|
|
20
|
-
|
|
54
|
+
// #5 - Add input validation
|
|
55
|
+
const solutionId = (args.solution_id as string || '').trim();
|
|
56
|
+
|
|
57
|
+
if (!solutionId) {
|
|
58
|
+
return {
|
|
59
|
+
content: [{ type: 'text', text: 'Error: solution_id cannot be empty. Please provide a valid solution ID from find_solution results.' }],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
21
63
|
const result = await client.unlockSolution(solutionId);
|
|
22
64
|
|
|
23
65
|
if (!result.success) {
|
|
66
|
+
// #6 - Improve error messages with context
|
|
67
|
+
const errorMessage = [
|
|
68
|
+
`❌ ${getErrorTitle(result.error || '')}`,
|
|
69
|
+
'',
|
|
70
|
+
result.error,
|
|
71
|
+
'',
|
|
72
|
+
'💡 **What to try:**',
|
|
73
|
+
getRecoverySuggestions(result.error || ''),
|
|
74
|
+
'',
|
|
75
|
+
`📋 **Logs**: Check ${config.logging.logDir || '~/.cache-overflow'}/cache-overflow-mcp.log for details`,
|
|
76
|
+
].join('\n');
|
|
77
|
+
|
|
24
78
|
return {
|
|
25
|
-
content: [{ type: 'text', text:
|
|
79
|
+
content: [{ type: 'text', text: errorMessage }],
|
|
26
80
|
};
|
|
27
81
|
}
|
|
28
82
|
|
package/src/types.ts
CHANGED
|
@@ -37,3 +37,51 @@ export interface User {
|
|
|
37
37
|
export type ApiResponse<T> =
|
|
38
38
|
| { success: true; data: T }
|
|
39
39
|
| { success: false; error: string };
|
|
40
|
+
|
|
41
|
+
// Remote MCP configuration types (fetched from backend)
|
|
42
|
+
|
|
43
|
+
export interface RemoteInputProperty {
|
|
44
|
+
type: string;
|
|
45
|
+
description: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface RemoteInputSchema {
|
|
49
|
+
type: string;
|
|
50
|
+
properties: Record<string, RemoteInputProperty>;
|
|
51
|
+
required: string[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface RemoteToolDefinition {
|
|
55
|
+
name: string;
|
|
56
|
+
description: string;
|
|
57
|
+
inputSchema: RemoteInputSchema;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface RemotePromptArgument {
|
|
61
|
+
name: string;
|
|
62
|
+
description: string;
|
|
63
|
+
required: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface RemotePromptMessageContent {
|
|
67
|
+
type: string;
|
|
68
|
+
text: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface RemotePromptMessage {
|
|
72
|
+
role: string;
|
|
73
|
+
content: RemotePromptMessageContent;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface RemotePromptDefinition {
|
|
77
|
+
name: string;
|
|
78
|
+
description: string;
|
|
79
|
+
arguments: RemotePromptArgument[];
|
|
80
|
+
messages: RemotePromptMessage[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface McpConfigResponse {
|
|
84
|
+
schema_version: string;
|
|
85
|
+
tools: RemoteToolDefinition[];
|
|
86
|
+
prompts: RemotePromptDefinition[];
|
|
87
|
+
}
|