Skip to content

Add bidirectional communication to local server#8

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/sub-pr-7
Draft

Add bidirectional communication to local server#8
Copilot wants to merge 6 commits intomainfrom
copilot/sub-pr-7

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 1, 2026

Extended bidirectional communication (sendNotification, sendRequest) from relay-only to both relay and local server implementations.

Changes

Local Server (mcp_server.lua)

  • Added sendNotification() and sendRequest() methods with message queue and callback tracking
  • Added /poll endpoint for long-polling (returns 204 when empty, 200 with message)
  • Added /response endpoint for client responses to server-initiated requests
  • Initialized instance-specific tables in constructor (following relay pattern)

Protocol Layer (mcp_protocol.lua)

  • Added transport abstraction via setTransport() to support both MCPServer and MCPRelay
  • Added notifyResourcesUpdated() to send resource update notifications through transport
  • Added checkAndNotifyResourceChanges() for automatic change detection and notification

Integration (main.lua)

  • Set transport on protocol when starting local or relay server
  • Added scheduleResourceChangeCheck() with 0.5s polling interval
  • Proper cleanup of resource check task on server stop

Usage

Both local and relay servers now support server→client communication:

-- Resource changes automatically trigger notifications
protocol:checkAndNotifyResourceChanges()  
-- Sends: {"jsonrpc":"2.0","method":"notifications/resources/updated","params":{"uri":"book://current/context"}}

-- Manual notifications
transport:sendNotification({
    jsonrpc = "2.0",
    method = "notifications/message",
    params = {level = "info", message = "Page changed"}
})

-- Bidirectional requests
transport:sendRequest({
    jsonrpc = "2.0",
    id = 1,
    method = "sampling/createMessage",
    params = {...}
}, function(response) 
    -- Handle response
end)

Enables MCP features requiring server→client communication: resource update notifications, logging, sampling requests, and elicitation in both deployment modes.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

laughedelic and others added 2 commits February 1, 2026 01:40
Add server-initiated message support to the cloud relay:
- sendNotification(): send JSON-RPC notifications to client
- sendRequest(): send JSON-RPC requests and handle responses
- handleServerResponse(): process responses from client

This enables MCP features that require server→client communication:
- Resource update notifications (notifications/resources/updated)
- Logging notifications (notifications/message)
- Sampling requests (sampling/createMessage)
- Elicitation requests (elicitation/create)

The relay now handles 'server_response' messages in the poll loop
and routes them to pending request callbacks.
Copilot AI and others added 4 commits February 1, 2026 00:59
- Added message queue and bidirectional communication methods to mcp_server.lua
- Added /poll endpoint for long-polling server-initiated messages
- Added sendNotification() and sendRequest() methods to MCPServer
- Added setTransport() to MCPProtocol for transport abstraction
- Added resource change monitoring and notification in both local and relay modes
- Wire up protocol to send notifications/resources/updated when resources change
- Both local server and relay now support same bidirectional patterns

Co-authored-by: laughedelic <[email protected]>
…dition

- Remove class-level defaults for instance-specific tables in MCPServer
- Add running state check at start of resource check task to avoid race conditions

Co-authored-by: laughedelic <[email protected]>
- Document that getNextRequestId is thread-safe in Lua's single-threaded event loop
- Explain rationale for 0.5s resource check interval (battery life balance)

Co-authored-by: laughedelic <[email protected]>
Copilot AI changed the title [WIP] Add bidirectional communication to relay Add bidirectional communication to local server Feb 1, 2026
Copilot AI requested a review from laughedelic February 1, 2026 01:04
Base automatically changed from feat/relay-bidirectional to main February 1, 2026 01:06
laughedelic added a commit that referenced this pull request Feb 1, 2026
- Update features list with subscriptions, client features (sampling, elicitation, logging)
- Expand resources table with library resources and resource templates
- Add tool annotations section explaining readOnlyHint, destructiveHint, etc.
- Add server-initiated features section (notifications, logging, sampling/elicitation)
- Note local mode limitations and link to PR #8 for bidirectional work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants