API

Server Types

  • MCPServerConfig
  • MCPServer
  • MCPRequestContext
  • MCPHTTPServer
  • MCPServerTool
  • MCPServerPrompt
  • MCPServerResource

Server Functions

  • register_tool!
  • register_prompt!
  • register_resource!
  • register_resource_template!
  • serve_mcp_http
  • stop_mcp_server
  • base_url
  • set_request_hook!
  • set_cancellation_handler!
  • set_logging_handler!
  • set_completion_handler!
  • log_message!
  • enqueue_server_event!
  • broadcast_server_event!
  • notify_resource_updated!

Trim-safe Static Server

These specialized names are not exported. Use them through the ModelContextProtocol namespace. See the static server guide for a complete example and the support limits.

  • ModelContextProtocol.StaticMCPServer
  • ModelContextProtocol.StaticMCPTool
  • ModelContextProtocol.StaticMCPToolResult
  • ModelContextProtocol.StaticMCPResource
  • ModelContextProtocol.StaticMCPRequestContext
  • ModelContextProtocol.static_ui_tool_meta
  • ModelContextProtocol.static_ui_extensions
  • ModelContextProtocol.handle_static_jsonrpc_request
  • ModelContextProtocol.handle_static_stream_request
  • ModelContextProtocol.handle_static_session_delete

MCP Events

These APIs are namespaced. See MCP Events for security hooks, persistence, delivery receipts, and protocol limits.

  • ModelContextProtocol.enable_events!
  • ModelContextProtocol.register_event!
  • ModelContextProtocol.emit_event!
  • ModelContextProtocol.InMemoryEventSubscriptionStore
  • ModelContextProtocol.FileEventSubscriptionStore
  • ModelContextProtocol.MCPEventSubscriptionStore
  • ModelContextProtocol.list_events
  • ModelContextProtocol.subscribe_event
  • ModelContextProtocol.unsubscribe_event
  • ModelContextProtocol.event_webhook_secret
  • ModelContextProtocol.verify_event_webhook

MCP Apps (SEP-1865)

Helpers for serving interactive HTML widgets that hosts render inline. See MCP-App-playbook.md for the full guide.

  • MCP_APPS_EXTENSION_ID
  • MCP_APP_HTML_MIME_TYPE
  • MCP_APPS_UI_PROTOCOL_VERSION
  • MCPUIResource
  • ui_extension_capability
  • add_ui_extension_capability!
  • ModelContextProtocol.supports_mcp_apps_ui
  • ui_tool_meta
  • ui_resource_meta
  • ui_resource_contents
  • embedded_ui_resource
  • ui_tool_content
  • register_ui_resource!
  • mcp_app_html
  • MCP_APP_BOOTSTRAP_JS

Client Types

  • MCPDiscovery
  • MCPTransportDescriptor
  • MCPClientConfig
  • MCPClient
  • MCPAuthenticationRequired
  • MCPAuthenticationChallenge

Client Functions

  • ModelContextProtocol.prepare_stdio_client
  • discover_server
  • prepare_manual_client
  • attach_token!
  • initialize_client!
  • list_tools
  • call_tool
  • list_prompts
  • get_prompt
  • list_resources
  • read_resource
  • list_resource_templates
  • subscribe_resource
  • unsubscribe_resource
  • completion_complete
  • set_log_level!
  • ping
  • open_event_stream
  • register_request_handler!
  • clear_request_handlers!
  • start_event_listener!
  • stop_event_listener!
  • terminate_session!

Owned stdio clients

ModelContextProtocol.prepare_stdio_client — Function
ModelContextProtocol.prepare_stdio_client(command::Cmd; config=MCPClientConfig(),
    stderr=Base.stderr, capabilities=Dict(), client_info=default_client_info(),
    max_message_bytes=16*1024*1024, max_pending_messages=128)

Launch and own a local MCP server process. Use initialize_client! and the ordinary client call APIs, then close(client) or terminate_session!. The do-block form closes the client even when its body throws. Register handlers and finish initialization before making concurrent calls.

Protocol selection is explicit: 2025-11-25 uses initialization and permits server requests; 2026-07-28 uses discovery and per-request metadata. HTTP headers, OAuth, HTTP event streams, and modern subscriptions are unsupported. There is no automatic protocol fallback, process restart, or request replay. Custom HTTP adapters and verbose HTTP logging are rejected.

config.timeout.readtimeout (seconds, positive and finite) bounds transport waits, including queued writes; per-call timeout_ms overrides it. The HTTP connecttimeout setting has no effect on process startup. Other timeout keys are rejected. A response timeout sends cancellation; a write timeout breaks the connection because a partial frame cannot be retried safely.

The byte limit applies to each incoming and outgoing message. The pending limit separately bounds calls, queued writes, queued notifications, and active server-request handlers. Callback overflow or invalid server output breaks the connection. Notifications run in order; legacy request handlers run in separate tasks and may overlap each other and notifications. A handler's nested call can receive another server request before it completes. Closing discards callbacks that have not started. User callbacks must cooperate with shutdown; see close(::MCPClient).

The child's stderr is redirected directly to a filename, IOStream, terminal, pipe, or devnull, separately from protocol stdout. In-memory and custom IO destinations are unsupported. Caller-provided IO remains caller-owned.

source
Base.close — Method
close(client::MCPClient; timeout=5.0)

For an owned stdio client, stop accepting calls, close stdin, then terminate and, if necessary, kill the child. Fail pending calls and wait for owned IO and callback tasks. timeout bounds this wait; unfinished cleanup is retained and a later close may finish it. The caller owns any custom stderr destination.

Julia cannot safely interrupt arbitrary user callback code. If a callback remains blocked after process/IO shutdown, throw MCPError(:callback_timeout); release the callback and close again. A callback that calls close waits for process and IO shutdown but not for user callback tasks, preventing callbacks that close concurrently from waiting on each other. A later external close waits for any unfinished callbacks. Queued callbacks are discarded. HTTP clients delegate to terminate_session!.

source

MCP 2026-07-28

The modern low-level helpers stay under the package namespace to keep the export surface small. See the MCP 2026-07-28 guide.

  • MCPInputRequired
  • ModelContextProtocol.PROTOCOL_VERSION_2026_07_28
  • ModelContextProtocol.discover_server_info!
  • ModelContextProtocol.is_input_required
  • ModelContextProtocol.input_responses
  • ModelContextProtocol.request_state
  • ModelContextProtocol.send_progress!
  • ModelContextProtocol.send_log!
  • ModelContextProtocol.listen_subscriptions!
  • ModelContextProtocol.close_subscription_listeners!