#!/usr/bin/env node
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
import { sendNotification } from './tools/notification.js';
import type { NotificationOptions } from './types/index.js';
const server = new Server(
{
name: 'mcp-macos-utils',
version: '1.0.0',
},
{
capabilities: {
tools: {},
},
}
);
// List available tools
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: 'notify',
description: 'Send a macOS notification with auto-detected project context',
inputSchema: {
type: 'object',
properties: {
title: {
type: 'string',
description: 'Notification title',
},
message: {
type: 'string',
description: 'Notification message',
},
type: {
type: 'string',
enum: ['success', 'error', 'info', 'warning'],
description: 'Type of notification (affects icon)',
default: 'info',
},
sound: {
type: 'boolean',
description: 'Whether to play a sound',
default: true,
},
subtitle: {
type: 'string',
description: 'Optional subtitle (defaults to project name)',
},
},
required: ['title', 'message'],
},
},
],
};
});
// Handle tool calls
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
switch (name) {
case 'notify': {
if (!args || typeof args !== 'object') {
throw new Error('Invalid arguments for notify tool');
}
const options: NotificationOptions = {
title: String(args.title || 'Notification'),
message: String(args.message || ''),
type: (args.type as NotificationOptions['type']) || 'info',
sound: Boolean(args.sound !== false),
subtitle: args.subtitle ? String(args.subtitle) : undefined,
};
const result = await sendNotification(options);
return {
content: [
{
type: 'text',
text: result.success
? `Notification sent successfully. Logged to: ${result.logPath}`
: `Failed to send notification: ${result.error}. Logged to: ${result.logPath}`,
},
],
};
}
default:
throw new Error(`Unknown tool: ${name}`);
}
});
// Start the server
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error('MCP macOS Utils Server running on stdio');
}
main().catch((error) => {
console.error('Fatal error:', error);
process.exit(1);
});