N
Neon4mo ago
sunny-green

Could not connect to Local Neon MCP Server

I'm building a slack bot which listens to messages and connects with neon MCP Server but after running npx -y @neondatabase/mcp-server-neon start neon_api_key it returns nothing to me and not sure what's going on. It does not connect. When I tried connecting via Cursor, it worked. It is not returning any error messages either to help me debug
3 Replies
frail-apricot
frail-apricot4mo ago
@kulkarniankita Can you please provide more details on it? How are you trying to connect to it? And possibly share screenshots to help debug.
sunny-green
sunny-greenOP4mo ago
@shriidhar I’m using an API to connect to it
1) I ran the local dev server
import { WebClient } from "@slack/web-api";

const slackToken = process.env.SLACK_BOT_TOKEN;
const neonMcpUrl = process.env.NEON_MCP_URL; // e.g., http://localhost:3000/mcp

const slackClient = new WebClient(slackToken);

// 'request' parameter is required for Next.js route handlers and is used below.
export async function POST(request) {
const body = await request.json();

// Slack URL verification challenge
if (body.type === "url_verification") {
return new Response(JSON.stringify({ challenge: body.challenge }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}

// Handle app_mention and direct messages (http://message.im)
if (
body.event &&
(body.event.type === "app_mention" ||
(body.event.type === "message" && http://body.event.channel_type === "im"))
) {
const event = body.event;
const userMessage = event.text.replace(/<@[^>]+>\s*/, "");
try {

const mcpResponse = await fetch(neonMcpUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: userMessage }),
});
const mcpData = await mcpResponse.json();
await http://slackClient.chat.postMessage({

channel: http://event.channel,
thread_ts: event.ts,
text: mcpData.reply || "No response from Neon MCP.",
});
} catch {
await http://slackClient.chat.postMessage({
channel: http://event.channel,
thread_ts: event.ts,
text: "Error connecting to Neon MCP.",
});
}
return new Response(null, { status: 200 });
}
// Default response
return new Response(null, { status: 200 });

}
export async function GET(request) {
return new Response("Hello, world!", { status: 200 });

}
1) I ran the local dev server
import { WebClient } from "@slack/web-api";

const slackToken = process.env.SLACK_BOT_TOKEN;
const neonMcpUrl = process.env.NEON_MCP_URL; // e.g., http://localhost:3000/mcp

const slackClient = new WebClient(slackToken);

// 'request' parameter is required for Next.js route handlers and is used below.
export async function POST(request) {
const body = await request.json();

// Slack URL verification challenge
if (body.type === "url_verification") {
return new Response(JSON.stringify({ challenge: body.challenge }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}

// Handle app_mention and direct messages (http://message.im)
if (
body.event &&
(body.event.type === "app_mention" ||
(body.event.type === "message" && http://body.event.channel_type === "im"))
) {
const event = body.event;
const userMessage = event.text.replace(/<@[^>]+>\s*/, "");
try {

const mcpResponse = await fetch(neonMcpUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: userMessage }),
});
const mcpData = await mcpResponse.json();
await http://slackClient.chat.postMessage({

channel: http://event.channel,
thread_ts: event.ts,
text: mcpData.reply || "No response from Neon MCP.",
});
} catch {
await http://slackClient.chat.postMessage({
channel: http://event.channel,
thread_ts: event.ts,
text: "Error connecting to Neon MCP.",
});
}
return new Response(null, { status: 200 });
}
// Default response
return new Response(null, { status: 200 });

}
export async function GET(request) {
return new Response("Hello, world!", { status: 200 });

}
2) and then ran this npx @neondatabase/mcp-server-neon start neon_api
frail-apricot
frail-apricot4mo ago
The npx start command starts the Neon MCP in stdio transport mode, it won't be listening on any HTTP port, so the fetch call won't help it connect. You might want to look into building MCP client that is also a slack bot. The MCP client can handle the message exchange between client and server. Quick search landed me to an example on Github - https://github.com/tuannvm/slack-mcp-client
GitHub
GitHub - tuannvm/slack-mcp-client: A Slack bot and MCP client acts ...
A Slack bot and MCP client acts as a bridge between Slack and Model Context Protocol (MCP) servers. Using Slack as the interface, it enables large language models (LLMs) to connect and interact wit...

Did you find this page helpful?