@kujirahand/discord-webhook-mcp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -0
  3. package/mcp_server.js +248 -0
  4. package/package.json +39 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kujirahand
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # discord-webhook-mcp
2
+
3
+ MCP Server for Discord webhook
4
+
5
+ ## Install to Antigravity CLI
6
+
7
+ ```sh
8
+ gemini mcp add discord-webhook \
9
+ node mcp_server.js \
10
+ --env DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/xxxxx
11
+ ```
12
+
13
+ ## Install to Codex CLI
14
+
15
+ ```sh
16
+ codex mcp add discord-webhook \
17
+ node mcp_server.js \
18
+ --env DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/xxxxx
19
+ ```
20
+
21
+ ## Install to Claude Code
22
+
23
+ ```sh
24
+ claude mcp add discord-webhook \
25
+ node mcp_server.js \
26
+ --env DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/xxxxx
27
+ ```
28
+
29
+ ## Available Tools
30
+
31
+ ### 1. `send_message`
32
+ Sends a text message to the Discord channel.
33
+ - **Arguments:**
34
+ - `message` (string, required): The text message.
35
+ - `username` (string, optional): Override the webhook bot's username.
36
+ - `avatar_url` (string, optional): Override the webhook bot's avatar.
37
+
38
+ ### 2. `send_image`
39
+ Uploads an image file to the Discord channel.
40
+ - **Arguments:**
41
+ - `image_path` (string, required): Local path to the image file.
42
+ - `message` (string, optional): Accompanying text message.
43
+ - `username` (string, optional): Override the webhook bot's username.
44
+ - `avatar_url` (string, optional): Override the webhook bot's avatar.
45
+
46
+
package/mcp_server.js ADDED
@@ -0,0 +1,248 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import {
5
+ CallToolRequestSchema,
6
+ ListToolsRequestSchema,
7
+ } from "@modelcontextprotocol/sdk/types.js";
8
+ import { z } from "zod";
9
+ import fs from "node:fs/promises";
10
+ import path from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+
13
+ // Zod schemas for validation
14
+ export const SendMessageSchema = z.object({
15
+ message: z.string().min(1, "message must be a non-empty string"),
16
+ username: z.string().optional(),
17
+ avatar_url: z.string().url("avatar_url must be a valid URL").optional(),
18
+ });
19
+
20
+ export const SendImageSchema = z.object({
21
+ image_path: z.string().min(1, "image_path must be a non-empty string"),
22
+ message: z.string().optional(),
23
+ username: z.string().optional(),
24
+ avatar_url: z.string().url("avatar_url must be a valid URL").optional(),
25
+ });
26
+
27
+ function getMimeType(filePath) {
28
+ const ext = path.extname(filePath).toLowerCase();
29
+ switch (ext) {
30
+ case ".png": return "image/png";
31
+ case ".jpg":
32
+ case ".jpeg": return "image/jpeg";
33
+ case ".gif": return "image/gif";
34
+ case ".webp": return "image/webp";
35
+ default: return "application/octet-stream";
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Handles the actual tool call execution.
41
+ * Extracted into a helper function to allow easy unit testing.
42
+ */
43
+ async function handleSendMessage(args, webhookUrl) {
44
+ const parsed = SendMessageSchema.safeParse(args);
45
+ if (!parsed.success) {
46
+ throw new Error(`Invalid arguments: ${parsed.error.issues.map(e => e.message).join(", ")}`);
47
+ }
48
+
49
+ const { message, username, avatar_url } = parsed.data;
50
+ const payload = { content: message };
51
+ if (username) payload.username = username;
52
+ if (avatar_url) payload.avatar_url = avatar_url;
53
+
54
+ const response = await fetch(webhookUrl, {
55
+ method: "POST",
56
+ headers: { "Content-Type": "application/json" },
57
+ body: JSON.stringify(payload),
58
+ });
59
+
60
+ if (!response.ok) {
61
+ const errorText = await response.text();
62
+ throw new Error(`Discord API responded with status ${response.status}: ${errorText}`);
63
+ }
64
+
65
+ return {
66
+ content: [
67
+ {
68
+ type: "text",
69
+ text: `Message successfully sent to Discord.`,
70
+ },
71
+ ],
72
+ };
73
+ }
74
+
75
+ async function handleSendImage(args, webhookUrl) {
76
+ const parsed = SendImageSchema.safeParse(args);
77
+ if (!parsed.success) {
78
+ throw new Error(`Invalid arguments: ${parsed.error.issues.map(e => e.message).join(", ")}`);
79
+ }
80
+
81
+ const { image_path, message, username, avatar_url } = parsed.data;
82
+
83
+ // Resolve path and check file existence
84
+ const resolvedPath = path.resolve(image_path);
85
+ try {
86
+ await fs.access(resolvedPath);
87
+ } catch {
88
+ throw new Error(`File not found: ${image_path}`);
89
+ }
90
+
91
+ const fileBuffer = await fs.readFile(resolvedPath);
92
+ const mimeType = getMimeType(resolvedPath);
93
+ const fileName = path.basename(resolvedPath);
94
+
95
+ const formData = new FormData();
96
+ const blob = new Blob([fileBuffer], { type: mimeType });
97
+ formData.append("files[0]", blob, fileName);
98
+
99
+ const payload = {};
100
+ if (message) payload.content = message;
101
+ if (username) payload.username = username;
102
+ if (avatar_url) payload.avatar_url = avatar_url;
103
+
104
+ formData.append("payload_json", JSON.stringify(payload));
105
+
106
+ const response = await fetch(webhookUrl, {
107
+ method: "POST",
108
+ body: formData,
109
+ });
110
+
111
+ if (!response.ok) {
112
+ const errorText = await response.text();
113
+ throw new Error(`Discord API responded with status ${response.status}: ${errorText}`);
114
+ }
115
+
116
+ return {
117
+ content: [
118
+ {
119
+ type: "text",
120
+ text: `Image successfully sent to Discord.`,
121
+ },
122
+ ],
123
+ };
124
+ }
125
+
126
+ /**
127
+ * Handles the actual tool call execution.
128
+ * Extracted into a helper function to allow easy unit testing.
129
+ */
130
+ export async function handleCallTool(name, args, env = process.env) {
131
+ const webhookUrl = env.DISCORD_WEBHOOK_URL;
132
+ if (!webhookUrl) {
133
+ throw new Error("DISCORD_WEBHOOK_URL environment variable is not set.");
134
+ }
135
+
136
+ switch (name) {
137
+ case "send_message":
138
+ return await handleSendMessage(args, webhookUrl);
139
+ case "send_image":
140
+ return await handleSendImage(args, webhookUrl);
141
+ default:
142
+ throw new Error(`Unknown tool: ${name}`);
143
+ }
144
+ }
145
+
146
+ const server = new Server(
147
+ {
148
+ name: "discord-webhook",
149
+ version: "1.0.0",
150
+ },
151
+ {
152
+ capabilities: {
153
+ tools: {},
154
+ },
155
+ }
156
+ );
157
+
158
+ // Register tools list handler
159
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
160
+ return {
161
+ tools: [
162
+ {
163
+ name: "send_message",
164
+ description: "Send a message to Discord via webhook",
165
+ inputSchema: {
166
+ type: "object",
167
+ properties: {
168
+ message: {
169
+ type: "string",
170
+ description: "The text message to send to Discord.",
171
+ },
172
+ username: {
173
+ type: "string",
174
+ description: "Optional username override for the webhook bot.",
175
+ },
176
+ avatar_url: {
177
+ type: "string",
178
+ description: "Optional avatar image URL override for the webhook bot.",
179
+ },
180
+ },
181
+ required: ["message"],
182
+ },
183
+ },
184
+ {
185
+ name: "send_image",
186
+ description: "Send an image to Discord via webhook",
187
+ inputSchema: {
188
+ type: "object",
189
+ properties: {
190
+ image_path: {
191
+ type: "string",
192
+ description: "The local file path (absolute or relative) to the image to upload.",
193
+ },
194
+ message: {
195
+ type: "string",
196
+ description: "Optional text message to accompany the image.",
197
+ },
198
+ username: {
199
+ type: "string",
200
+ description: "Optional username override for the webhook bot.",
201
+ },
202
+ avatar_url: {
203
+ type: "string",
204
+ description: "Optional avatar image URL override for the webhook bot.",
205
+ },
206
+ },
207
+ required: ["image_path"],
208
+ },
209
+ },
210
+ ],
211
+ };
212
+ });
213
+
214
+ // Register tool execution handler
215
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
216
+ try {
217
+ const { name, arguments: args } = request.params;
218
+ return await handleCallTool(name, args);
219
+ } catch (error) {
220
+ return {
221
+ isError: true,
222
+ content: [
223
+ {
224
+ type: "text",
225
+ text: error.message,
226
+ },
227
+ ],
228
+ };
229
+ }
230
+ });
231
+
232
+ async function main() {
233
+ const transport = new StdioServerTransport();
234
+ await server.connect(transport);
235
+ console.error("Discord Webhook MCP Server running on stdio");
236
+ }
237
+
238
+ const isMain = process.argv[1] && (
239
+ process.argv[1] === fileURLToPath(import.meta.url) ||
240
+ process.argv[1].endsWith("mcp_server.js")
241
+ );
242
+
243
+ if (isMain) {
244
+ main().catch((error) => {
245
+ console.error("Fatal error in main():", error);
246
+ process.exit(1);
247
+ });
248
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@kujirahand/discord-webhook-mcp",
3
+ "version": "1.0.0",
4
+ "description": "MCP Server for Discord webhook",
5
+ "main": "mcp_server.js",
6
+ "bin": {
7
+ "discord-webhook-mcp": "./mcp_server.js"
8
+ },
9
+ "files": [
10
+ "mcp_server.js"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "type": "module",
16
+ "scripts": {
17
+ "test": "node --test tests/*.js"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/kujirahand/discord-webhook-mcp.git"
22
+ },
23
+ "keywords": [
24
+ "mcp",
25
+ "model-context-protocol",
26
+ "discord",
27
+ "webhook"
28
+ ],
29
+ "author": "",
30
+ "license": "MIT",
31
+ "bugs": {
32
+ "url": "https://github.com/kujirahand/discord-webhook-mcp/issues"
33
+ },
34
+ "homepage": "https://github.com/kujirahand/discord-webhook-mcp#readme",
35
+ "dependencies": {
36
+ "@modelcontextprotocol/sdk": "^1.29.0",
37
+ "zod": "^4.4.3"
38
+ }
39
+ }