Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,58 @@ pnpm run build
}
```

### Running on Localhost (HTTP Server)

You can run the MCP server as an HTTP server on localhost for testing or integration with web applications.

1. **Build the project** (if you haven't already):

```bash
pnpm install
pnpm run build
```

2. **Set your API key**:

```bash
export RESEND_API_KEY=re_your_key_here
```

3. **Start the HTTP server**:

```bash
pnpm run dev
```

Or with a custom port:

```bash
node build/index.js --http --port 8080 --key=re_your_key_here
```

4. **Access the server**:

- **Health check**: http://localhost:3000/health
- **MCP endpoint**: http://localhost:3000/mcp

The HTTP server supports:
- **POST /mcp**: Send MCP requests (JSON-RPC)
- **GET /mcp**: Server-Sent Events (SSE) streaming for long-running operations
- **GET /sse**: SSE endpoint for ChatGPT compatibility
- **GET /health**: Health check endpoint

**ChatGPT Custom Apps:**
- Use `http://localhost:3000/mcp` or `http://localhost:3000/sse` as the server URL
- The server supports both MCP Apps and ChatGPT Apps SDK protocols
- Interactive email composition UI is available via the `compose_email` tool

**Command-line options for HTTP mode:**
- `--http` or `--server`: Enable HTTP server mode
- `--port` or `-p`: Set the port (default: 3000)
- `--key`: Your Resend API key (or use `RESEND_API_KEY` environment variable)
- `--sender`: Sender email address (optional)
- `--reply-to`: Reply-to email address (optional)

### Testing with MCP Inspector

> **Note:** Make sure you've built the project first (see [Setup](#setup) section above).
Expand Down
18 changes: 14 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
import minimist from 'minimist';
import { Resend } from 'resend';
import packageJson from './package.json' with { type: 'json' };
import { startHttpServer } from './server/http.js';
import {
addApiKeyTools,
addBroadcastTools,
addComposeEmailTool,
addContactPropertyTools,
addContactTools,
addDomainTools,
Expand Down Expand Up @@ -46,7 +48,6 @@ if (!apiKey) {

const resend = new Resend(apiKey);

// Create server instance
const server = new McpServer({
name: 'email-sending-service',
version: packageJson.version,
Expand All @@ -61,14 +62,23 @@ addContactPropertyTools(server, resend);
addContactTools(server, resend);
addDomainTools(server, resend);
addEmailTools(server, resend, { senderEmailAddress, replierEmailAddresses });
addComposeEmailTool(server, resend, {
senderEmailAddress,
replierEmailAddresses,
});
addSegmentTools(server, resend);
addTopicTools(server, resend);
addWebhookTools(server, resend);

async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error('Email sending service MCP Server running on stdio');
if (argv.http || argv.server) {
const port = argv.port || argv.p || process.env.PORT || 3000;
await startHttpServer(server, port);
} else {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error('Email sending service MCP Server running on stdio');
}
}

main().catch((error) => {
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
"dist"
],
"scripts": {
"dev": "node dist/index.js --http --port 3000",
"start": "node dist/index.js",
"build": "tsc && node -e \"require('fs').chmodSync('dist/index.js', '755')\"",
"prepare": "npm run build",
"inspector": "npx @modelcontextprotocol/inspector@latest",
"lint": "biome check .",
"lint:fix": "biome check . --write"
},
"dependencies": {
"@mcp-ui/server": "^6.0.1",
"@modelcontextprotocol/sdk": "1.25.2",
"express": "^5.2.1",
"minimist": "1.2.8",
"resend": "6.9.1",
"zod": "4.3.6"
Expand All @@ -27,6 +31,7 @@
},
"devDependencies": {
"@biomejs/biome": "2.3.10",
"@types/express": "^5.0.0",
"@types/minimist": "1.2.5",
"@types/node": "25.0.3",
"typescript": "5.9.3"
Expand Down
Loading
Loading