Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created June 28, 2025 14:49
Show Gist options
  • Save ngauthier/a60af242c06bd37786b7be33030adbe3 to your computer and use it in GitHub Desktop.
Save ngauthier/a60af242c06bd37786b7be33030adbe3 to your computer and use it in GitHub Desktop.
Drip MCP Server
#!/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 fetch from "node-fetch";
class DripAPI {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = "https://api.getdrip.com/v2";
}
getAuthHeader() {
return `Basic ${Buffer.from(`${this.apiKey}:`).toString('base64')}`;
}
async listAccounts() {
const response = await fetch(`${this.baseUrl}/accounts`, {
method: 'GET',
headers: {
'Authorization': this.getAuthHeader(),
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`Drip API error: ${response.status} ${response.statusText}`);
}
const data = await response.json();
return data.accounts;
}
}
const server = new Server(
{
name: "drip-mcp",
version: "0.1.0",
},
{
capabilities: {
tools: {},
},
}
);
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "echo",
description: "Echo back the provided text",
inputSchema: {
type: "object",
properties: {
text: {
type: "string",
description: "Text to echo back",
},
},
required: ["text"],
},
},
{
name: "list_accounts",
description: "List all Drip accounts",
inputSchema: {
type: "object",
properties: {
api_key: {
type: "string",
description: "Drip API key for authentication",
},
},
required: ["api_key"],
},
},
],
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
if (name === "echo") {
return {
content: [
{
type: "text",
text: `Echo: ${args?.text || ""}`,
},
],
};
}
if (name === "list_accounts") {
try {
const dripApi = new DripAPI(args?.api_key);
const accounts = await dripApi.listAccounts();
return {
content: [
{
type: "text",
text: `Found ${accounts.length} Drip accounts:\n\n${accounts.map(account =>
`• ${account.name} (ID: ${account.id})${account.url ? ` - ${account.url}` : ''}`
).join('\n')}`,
},
],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error fetching accounts: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
isError: true,
};
}
}
throw new Error(`Unknown tool: ${name}`);
});
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
main().catch((error) => {
console.error("Server error:", error);
process.exit(1);
});
{
"name": "drip-mcp",
"version": "0.1.0",
"description": "A minimal MCP server",
"type": "module",
"main": "index.js",
"bin": {
"drip-mcp": "index.js"
},
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^0.5.0",
"node-fetch": "^3.3.0"
},
"engines": {
"node": ">=18"
}
}
#!/usr/bin/env node
import { spawn } from 'child_process';
const server = spawn('node', ['index.js'], {
stdio: ['pipe', 'pipe', 'inherit']
});
// Test MCP protocol - initialize
const initMessage = {
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {
tools: {}
},
clientInfo: {
name: "test-client",
version: "0.1.0"
}
}
};
server.stdin.write(JSON.stringify(initMessage) + '\n');
// Test listing tools
const listToolsMessage = {
jsonrpc: "2.0",
id: 2,
method: "tools/list",
params: {}
};
setTimeout(() => {
server.stdin.write(JSON.stringify(listToolsMessage) + '\n');
}, 100);
// Test calling echo tool
const callToolMessage = {
jsonrpc: "2.0",
id: 3,
method: "tools/call",
params: {
name: "echo",
arguments: {
text: "Hello MCP!"
}
}
};
// Test calling list_accounts tool (will fail without real API key)
const listAccountsMessage = {
jsonrpc: "2.0",
id: 4,
method: "tools/call",
params: {
name: "list_accounts",
arguments: {
api_key: "test_key_will_fail"
}
}
};
setTimeout(() => {
server.stdin.write(JSON.stringify(callToolMessage) + '\n');
}, 200);
setTimeout(() => {
server.stdin.write(JSON.stringify(listAccountsMessage) + '\n');
}, 300);
server.stdout.on('data', (data) => {
console.log('Server response:', data.toString());
});
setTimeout(() => {
server.kill();
}, 1500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment