Class: Mathpix::MCP::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/mathpix/mcp/server.rb

Overview

MCP Server for Mathpix OCR.

Uses the official Ruby MCP SDK. Provides 9 tools as thin delegates to Mathpix::Client over the stdio transport.

Examples:

Start STDIO server

require 'mathpix/mcp'

Mathpix.configure do |config|
  config.app_id = ENV['MATHPIX_APP_ID']
  config.app_key = ENV['MATHPIX_APP_KEY']
end

Mathpix::MCP::Server.run

With custom configuration

server = Mathpix::MCP::Server.new(
  name: "mathpix-custom",
  version: "1.0.0",
  mathpix_client: custom_client
)
transport = server.create_stdio_transport
transport.open

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: 'mathpix', version: Mathpix::VERSION, mathpix_client: nil) ⇒ Server

Initialize MCP server

Parameters:

  • name (String) (defaults to: 'mathpix')

    server name

  • version (String) (defaults to: Mathpix::VERSION)

    server version

  • mathpix_client (Mathpix::Client) (defaults to: nil)

    optional client instance



53
54
55
56
57
58
# File 'lib/mathpix/mcp/server.rb', line 53

def initialize(name: 'mathpix', version: Mathpix::VERSION, mathpix_client: nil)
  @name = name
  @version = version
  @mathpix_client = mathpix_client || Mathpix.client
  @mcp_server = create_mcp_server
end

Instance Attribute Details

#mathpix_clientObject (readonly)

Returns the value of attribute mathpix_client.



46
47
48
# File 'lib/mathpix/mcp/server.rb', line 46

def mathpix_client
  @mathpix_client
end

#mcp_serverObject (readonly)

Returns the value of attribute mcp_server.



46
47
48
# File 'lib/mathpix/mcp/server.rb', line 46

def mcp_server
  @mcp_server
end

#nameObject (readonly)

Returns the value of attribute name.



46
47
48
# File 'lib/mathpix/mcp/server.rb', line 46

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



46
47
48
# File 'lib/mathpix/mcp/server.rb', line 46

def version
  @version
end

Class Method Details

.runObject

Class method: run server directly

Examples:

Mathpix::MCP::Server.run


88
89
90
# File 'lib/mathpix/mcp/server.rb', line 88

def self.run(**)
  new(**).run
end

Instance Method Details

#capabilitiesHash

Server capabilities

Returns:

  • (Hash)

    MCP server capabilities



78
79
80
81
82
# File 'lib/mathpix/mcp/server.rb', line 78

def capabilities
  {
    tools: tool_classes.map(&:name)
  }
end

#create_stdio_transport::MCP::Server::Transports::StdioTransport

Create STDIO transport (standard MCP transport)

Returns:

  • (::MCP::Server::Transports::StdioTransport)


63
64
65
# File 'lib/mathpix/mcp/server.rb', line 63

def create_stdio_transport
  ::MCP::Server::Transports::StdioTransport.new(@mcp_server)
end

#runObject

Run MCP server with STDIO transport (blocking)

Standard way to run MCP server via stdio



70
71
72
73
# File 'lib/mathpix/mcp/server.rb', line 70

def run
  transport = create_stdio_transport
  transport.open
end