node-server #10

Merged
Peter.Morton merged 7 commits from node-server into main 2026-04-30 20:46:52 -05:00
Owner
No description provided.
Peter.Morton added 7 commits 2026-04-30 20:46:33 -05:00
The previous implementation prefixed base64 with "BASE64:" in a text
response. This updates the response to use the proper MCP embedded
resource format:

  { type: "resource", resource: { uri, mimeType, blob } }

Changes:
- types.ts: extend ToolOutput content union to allow resource items
- file-operations.ts:
  - getMimeType() maps common extensions to MIME types, falling back
    to application/octet-stream
  - MIME_TYPES table covers PDF, ZIP, images, Office formats, audio/video
  - Binary files are now returned as an EmbeddedResource with:
      uri:      obsidian://<vault>/<path>
      mimeType: detected from file extension
      blob:     base64-encoded raw bytes from the Buffer
  - Tool descriptions updated to document the resource response shape

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Images (PNG, JPG, GIF, WEBP, SVG) now returned as { type: 'image', data, mimeType }
per https://modelcontextprotocol.io/specification/2025-11-25/server/tools#image-content
Other binary files continue using embedded resource format { type: 'resource', ... }
Added audio content type to ToolOutput union for future use

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds src/http-server.ts - a Node.js HTTP entry point that exposes the
MCP implementation via Streamable HTTP transport (POST/GET /mcp) per
the MCP 2025-11-25 specification.

- Uses StreamableHTTPServerTransport (stateless mode) from the MCP SDK
- Port configurable via MCP_PORT env var (default: 3000)
- ObsidianMCPServer.connect() now accepts an optional Transport param
  so both stdio (existing) and HTTP (new) modes reuse the same server
- Added 'npm run server' script to start the HTTP server

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Obsidian CLI does not support binary file output, causing corrupted
or empty results for images, PDFs, ZIPs, etc.

New approach for binary files (known MIME type from extension):
- Run 'obsidian vault info=path' to get the vault root filesystem path
- If 'file' param: run 'obsidian file file=<name>' and parse the 'path'
  field from its output to get the vault-relative path
- If 'path' param: use it directly as the vault-relative path
- Read the file with Node fs.readFile() and return as MCP content

Images -> { type: 'image', data, mimeType }
Other binary -> { type: 'resource', resource: { uri, mimeType, blob } }

Unknown extensions fall through to the CLI with a runtime binary
detection fallback that also uses native FS if triggered.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Peter.Morton merged commit 3d91406c2c into main 2026-04-30 20:46:52 -05:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: verint.com/obsidian-mcp#10