← All notes

Build an MCP server that exposes tools, and do not write logs to stdout

Answer: Build a small MCP server that exposes tools a host can call. Log to stderr, because writing to stdout will corrupt the JSON-RPC messages and break your server. A host such as Gemini CLI can then discover and execute those tools.

Why it matters

The official tutorial builds a simple MCP weather server and connects it to a host. We'll build a server that exposes two tools: get_alerts and get_forecast. MCP servers can provide three main types of capabilities, including tools, which are functions that can be called by the LLM with user approval. When you test from a desktop host, pass the absolute path to your server.

On stdio transports, writing to stdout will corrupt the JSON-RPC messages and break your server. Use the standard library logging module, which writes to stderr. Create one logger per module and call it from your tools. For HTTP-based servers, standard output logging is fine because it does not interfere with HTTP responses.

An MCP server is an application that exposes tools and resources to the Gemini CLI. It can list tool descriptions and parameters through standardized schema definitions, and it can execute tools with defined arguments.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Model Context Protocol, Build an MCP server, CC BY 4.0; Gemini CLI, MCP servers, Apache-2.0. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Model Context Protocol, Build an MCP server, CC BY 4.0; Gemini CLI, MCP servers, Apache-2.0.

Cite this

Permanent ID: iil:note:f3c7g4vk

iinventedlight. 2026. "Build an MCP server that exposes tools, and do not write logs to stdout." iinventedlight Library, iil:note:f3c7g4vk, version of 2026-11-22. https://iinventedlight.com/library/notes/building-an-mcp-server/. License: CC-BY-4.0.

@misc{iil_note_f3c7g4vk,
  author = {{iinventedlight}},
  title = {{Build an MCP server that exposes tools, and do not write logs to stdout}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-22},
  url = {https://iinventedlight.com/library/notes/building-an-mcp-server/},
  note = {Permanent ID iil:note:f3c7g4vk. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/building-an-mcp-server.md.