see this repo. this is for mcp server for google tasks. I want to create similar mcp…
- User
see this repo. this is for mcp server for google tasks. I want to create similar mcp server for mailchimp. can you help?
- Assistant
see this repo. this is for mcp server for google tasks. I want to create similar mcp server for mailchimp. can you help?
Certainly! To create an MCP server for Mailchimp similar to the gtasks-mcp server in the provided repository, you’ll need to follow a similar architecture and implementation pattern. Here's how you can approach the development process:
Familiarize Yourself with Mailchimp API:
Identify Use Cases:
Use the gtasks-mcp repository as a reference.
Directory Structure:
/src
- Mailchimp.ts (Handles Mailchimp API interactions)
- index.ts (Sets up the MCP server and defines tools/resources)
/dist (Generated after building the project)
/README.md (Documentation for your server)
package.json (Dependencies and scripts)
tsconfig.json (TypeScript configuration)
gcp-oauth.keys.json (OAuth credentials file for Google Tasks, replace with Mailchimp-specific auth storage)
Components:
Mailchimp.ts: A class to encapsulate Mailchimp API interactions (e.g., list audiences, create campaigns).index.ts): Define the tools and resources using the MCP SDK to expose Mailchimp functionalities.Authentication:
.env or a JSON file like mailchimp-credentials.json).Initialize the project:
mkdir mailchimp-mcp
cd mailchimp-mcp
npm init -y
npm install @modelcontextprotocol/sdk axios dotenv typescript --save
npm install @types/node --save-dev
Configure TypeScript:
Create a tsconfig.json file:
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
Secure API keys:
dotenv for environment variable management:
npm install dotenv
.env file to store your API key:
MAILCHIMP_API_KEY=your-mailchimp-api-key
MAILCHIMP_SERVER_PREFIX=usXX # Replace with your Mailchimp server prefix
Add a Mailchimp.ts file in the src folder to handle API interactions.
Create the Mailchimp.ts file to interact with Mailchimp's API.
import axios from "axios";
export class Mailchimp {
private apiKey: string;
private serverPrefix: string;
constructor(apiKey: string, serverPrefix: string) {
this.apiKey = apiKey;
this.serverPrefix = serverPrefix;
}
private getApiUrl(endpoint: string): string {
return `https://${this.serverPrefix}.api.mailchimp.com/3.0${endpoint}`;
}
private getHeaders() {
return {
Authorization: `Bearer ${this.apiKey}`,
"Content-Type": "application/json",
};
}
async listAudiences() {
const response = await axios.get(this.getApiUrl("/lists"), {
headers: this.getHeaders(),
});
return response.data;
}
async getAudienceDetails(audienceId: string) {
const response = await axios.get(this.getApiUrl(`/lists/${audienceId}`), {
headers: this.getHeaders(),
});
return response.data;
}
async createCampaign(payload: any) {
const response = await axios.post(this.getApiUrl("/campaigns"), payload, {
headers: this.getHeaders(),
});
return response.data;
}
async updateCampaign(campaignId: string, payload: any) {
const response = await axios.patch(
this.getApiUrl(`/campaigns/${campaignId}`),
payload,
{ headers: this.getHeaders() },
);
return response.data;
}
async deleteCampaign(campaignId: string) {
await axios.delete(this.getApiUrl(`/campaigns/${campaignId}`), {
headers: this.getHeaders(),
});
}
}
Create the index.ts file to define tools and resources.
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { CallToolRequest } from "@modelcontextprotocol/sdk/types.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { Mailchimp } from "./Mailchimp.js";
import dotenv from "dotenv";
dotenv.config();
const mailchimp = new Mailchimp(
process.env.MAILCHIMP_API_KEY!,
process.env.MAILCHIMP_SERVER_PREFIX!,
);
const server = new Server(
{ name: "example-servers/mailchimp", version: "0.1.0" },
{ capabilities: { resources: {}, tools: {} } },
);
server.setRequestHandler(CallToolRequest, async (request) => {
const { name, arguments: args } = request.params;
if (name === "listAudiences") {
const audiences = await mailchimp.listAudiences();
return {
content: [{ type: "text", text: JSON.stringify(audiences, null, 2) }],
isError: false,
};
}
if (name === "getAudienceDetails") {
const audienceId = args?.audienceId;
const details = await mailchimp.getAudienceDetails(audienceId);
return {
content: [{ type: "text", text: JSON.stringify(details, null, 2) }],
isError: false,
};
}
if (name === "createCampaign") {
const payload = args?.payload;
const campaign = await mailchimp.createCampaign(payload);
return {
content: [{ type: "text", text: `Campaign created: ${campaign.id}` }],
isError: false,
};
}
throw new Error("Tool not found");
});
const transport = new StdioServerTransport();
server.connect(transport);
Define the tools that your server provides in index.ts.
server.setRequestHandler(CallToolRequest, async () => {
return {
tools: [
{
name: "listAudiences",
description: "List all Mailchimp audiences",
inputSchema: {},
},
{
name: "getAudienceDetails",
description: "Get details of a specific audience",
inputSchema: {
type: "object",
properties: {
audienceId: { type: "string", description: "Audience ID" },
},
required: ["audienceId"],
},
},
{
name: "createCampaign",
description: "Create a new Mailchimp campaign",
inputSchema: {
type: "object",
properties: {
payload: {
type: "object",
description: "Campaign payload",
},
},
required: ["payload"],
},
},
],
};
});
Run the server with:
npm run start
Test the tools using the MCP SDK or integrate it with an MCP-compatible client.
Deploy the server using a cloud provider like AWS, GCP, or Heroku.
Create a README.md file to document the server, similar to gtasks-mcp.
Feel free to ask for clarification or additional help!