Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1broseidon Ketch mcp Server Close

From Leeroopedia
Knowledge Sources
Domains MCP, Server_Lifecycle
Last Updated 2026-10-27 00:00 GMT

Overview

Releases the server-lifetime resources: kills the headless browser if one was launched and closes the page cache (a no-op, since it holds nothing open).

Description

Close releases what `NewServer` constructed: it calls `scraper.Close()` (which kills the headless browser conn) and `cache.Close()` (a no-op kept for symmetry — the page cache opens its file per transaction per ADR-0006). Safe to call once `Run` has returned. Run runs the server over a transport until the client disconnects or the context is cancelled (SIGINT/SIGTERM via main.go).

Usage

Always `defer server.Close()` after `NewServer`. `Run` is called over a `&mcpsdk.StdioTransport{}` by `ketch mcp serve`.

Code Reference

Source Location

  • Repository: ketch
  • File: mcp/server.go, cmd/mcp.go

Signature

// Run runs the server over the given transport until disconnect or ctx cancel.
func (s *Server) Run(ctx context.Context, t mcpsdk.Transport) error

// Close releases server-lifetime resources. Safe to call once Run has returned.
func (s *Server) Close()

Import

import (
	"context"
	mcpsdk "github.com/modelcontextprotocol/go-sdk/mcp"
	"github.com/1broseidon/ketch/mcp"
)

I/O Contract

Inputs (Run)

Name Type Required Description
ctx context.Context Yes Cancelled by SIGINT/SIGTERM
t mcpsdk.Transport Yes Usually &mcpsdk.StdioTransport{}

Outputs (Run)

Name Type Description
return error Run failure (CLI maps to exit 4)

Usage Examples

Serve Lifecycle

server, err := mcp.NewServer(cfg, version)
if err != nil { return err } // exit 5
defer server.Close()
if err := server.Run(ctx, &mcpsdk.StdioTransport{}); err != nil {
	return err // exit 4
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment