import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
function createServer(): McpServer {
const server = new McpServer({
name: 'ShellAgent MCP Server',
version: process.env.VERSION || '0.0.1',
});
// // Validate required environment variables
// const SHELL_ACCESS_TOKEN = process.env.SHELL_ACCESS_TOKEN;
// if (!SHELL_ACCESS_TOKEN) {
// throw new Error('SHELL_ACCESS_TOKEN environment variable is required');
// }
// === Tools ===
server.tool(
'get_app_info',
'Get application information using app_id',
{
app_id: z.string().describe('The ID of the application to fetch information for'),
},
async (args) => {
try {
// Validate required environment variables at runtime
const SHELL_ACCESS_TOKEN = process.env.SHELL_ACCESS_TOKEN;
if (!SHELL_ACCESS_TOKEN) {
return {
isError: true,
content: [
{
type: 'text',
text: 'Error: SHELL_ACCESS_TOKEN environment variable is required. Please set it before using this tool.',
},
],
};
}
const response = await fetch('/api/get_app_info', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${SHELL_ACCESS_TOKEN}`
},
body: JSON.stringify({ app_id: args.app_id })
});
if (!response.ok) {
throw new Error(`Failed to fetch app info: ${response.statusText}`);
}
const appInfo = await response.json();
return {
isError: false,
content: [
{
type: 'text',
text: JSON.stringify(appInfo, null, 2),
},
],
};
} catch (error) {
return {
isError: true,
content: [
{
type: 'text',
text: `Error fetching app info: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
};
}
},
);
return server;
}
export { createServer };