import { z } from 'zod';
import type { MCPTool, MCPToolHandler } from '../types.js';
import { getApiBaseUrl } from '../utils/api.js';
export const memoGetTool: MCPTool = {
name: 'memo_get',
description: 'Retrieves a specific memo by its ID. Returns detailed memo information including content, metadata, and relationships.',
inputSchema: {
type: 'object',
properties: {
memoId: {
type: 'string',
description: 'ID of the memo to retrieve'
}
},
required: ['memoId']
}
};
export const handleMemoGet: MCPToolHandler = async (args: any) => {
try {
const schema = z.object({
memoId: z.string()
});
const { memoId } = schema.parse(args);
const response = await fetch(`${getApiBaseUrl()}/api/memos/${memoId}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({})) as { error?: string };
if (response.status === 404) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: false,
error: `Memo with ID ${memoId} not found`,
memo: null
})
}
]
};
}
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: false,
error: `API Error: ${response.statusText} - ${errorData.error || 'Unknown error'}`,
memo: null
})
}
]
};
}
const result = await response.json() as { memo: any };
// Deny access to secret memos
if (result.memo && result.memo.isSecret) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: false,
error: 'Access to secret memo is not allowed',
memo: null
})
}
]
};
}
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: true,
memo: result.memo
})
}
]
};
} catch (error: unknown) {
const errorMessage = error instanceof Error ? error.message : String(error);
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: false,
error: `Error occurred during memo retrieval: ${errorMessage}`,
memo: null
})
}
]
};
}
};