I’m working on building an MCP Server that can be accessed remotely via SSE.
As Ive seen, most freely available, MCP Servers have to be accessed locally via command and they proxy out to whatever RESTful service they access.
My use case is to simply give a client a URL and a Key and they can interface with their project using the LLM. But they don’t have access to any of the project’s resources, so an SSE connection is required.
I’m also a PHP server developer, so Im not going to use JavaScript or Python to implement the Server. But the MCP Prototcol is language agnostic and I know how to make my server reply in text/event-stream
I also understand the initial workflow for an MCP client is thusly:
Client - Ping the SSE server’s entry point
Server - Respond with a messages URL and a session token
Client - Ping the messages URL, sending the session token and a body of info to the “initialize” method
Server - Respond with a similar body exposing the features available to the agent
Client - Ping the messages URL, to the “initialized” method
Server - Respond with ok
In any case, I’m at part 4 of the rundown above and it seems no matter what I send it, I can’t get the Cursor or MCP Inspector clients to say anything accept
Error from MCP server: SseError: SSE error: undefined
I’m def on the struggle bus to find some kind of log do determine what part of my response these clients are whining about, but I can’t shake it.
Has anyone had a similar issue they’ve been able to resolve? I don’t care what language you used, I only care about the response shape, so any help is appreciated. Alot of MCP Server packages are vibe coded, which is cool and also seems appropriate but they don’t work!
I suggest using the MCP Inspector (Anthropic?) on an MCP that works in Cursor (as simple as possible), check format of input/output and ensure to have same structure. There are sometimes gotchas.
Cursor has same (bottom) Panel “Output” as Vscode and go there to Cursor MCP or other logs.
The SSE I use are very specific cases that are not publicly available as code.
I do recall other MCP devs in the forum discussing the same, perhaps search on top for MCP SSE or even more specific with tools, or initialize, as others had this case.
For anyone on the strugglebus in any language having connection issues with getting SSE working within your project, here’s what worked for me -
Firstly, this solution involves redis.
Secondly, this solution should work on single threaded languages, I’m just using PHP 8.2 if you’re using PHP, Im sure ReactPHP or Laravel Octane would make things even better.
Next, when the Agent/Client pings your server at the entry URL, that’s where you set up your session, open a stream and push out to that stream the uri you want it to send POSTs messages to. Don’t close it! For me, I made a data object containing the session id and a “queue” array of event objects to process and saved the object to the cache. DB might work too, but we’re aiming for no migrations. Make your stream loop and check that session object for a non empty set of pending events and process the next or just keep looping
When the client responds again with a POST call to the messages URL with. an initialize method request, you validate and process the request by loading your session dataobject with the queue in it and add a new event that was the product of your processing and then save the object back into the cache and return an empty 202 Accepted response.
The post call will return nothing but successfully and your stream on the other “request” will end up sending the event to the stream that’s opened. From there, the MCP client will complain at your craptastically formed, request or it will move on!
I hope this helps anyone about to throw their closest AI powered device out the fricken window (not in this economy!)