---
source: https://iinventedlight.com/library/notes/building-an-mcp-server.md
title: "Build an MCP server that exposes tools, and do not write logs to stdout"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (MCP documentation); Apache-2.0 (Gemini CLI docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Model Context Protocol, Build an MCP server, CC BY 4.0; Gemini CLI, MCP servers, Apache-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-22
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-22
as_of: 2026-11-22
confidence: medium
untested: "Not reproduced (2026-11-22). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coverage-gaps
topic_area: "how-to: building an MCP server"
tags: [agents, mcp, tools, servers, gemini-cli]
client: Librarian
sources:
  - id: S1
    title: "Build an MCP server"
    publisher: Model Context Protocol
    url: https://modelcontextprotocol.io/docs/2026-07-28/develop/build-server
    accessed: 2026-11-22
    license: "CC-BY-4.0"
  - id: S2
    title: "MCP servers with Gemini CLI"
    publisher: Gemini CLI
    url: https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md
    accessed: 2026-11-22
    license: "Apache-2.0"
---
# 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.

- `Expose tools` The tutorial server exposes `get_alerts` and `get_forecast`
- `Log to stderr` Writing to stdout will corrupt the JSON-RPC messages
- `Host discovery` List available tools, their descriptions, and parameters

## See also

- [writing-tool-descriptions](https://iinventedlight.com/library/notes/writing-tool-descriptions/)
- [ao-mcp](https://iinventedlight.com/library/notes/ao-mcp/)
- [ao-fastmcp](https://iinventedlight.com/library/notes/ao-fastmcp/)

## Claims

- id: C1
  claim: Writing to stdout will corrupt JSON-RPC messages and break a stdio MCP server.
  source: S1
  evidence: "Writing to stdout will corrupt the JSON-RPC messages and break your server."

- id: C2
  claim: The official tutorial builds a server that exposes get_alerts and get_forecast tools.
  source: S1
  evidence: "We'll build a server that exposes two tools: `get_alerts` and `get_forecast`."

- id: C3
  claim: An MCP server exposes tools and resources to Gemini CLI through the protocol.
  source: S2
  evidence: "An MCP server is an application that exposes tools and resources"

## Sources

- [S1] Build an MCP server. Model Context Protocol. https://modelcontextprotocol.io/docs/2026-07-28/develop/build-server . License: CC-BY-4.0. Accessed 2026-11-22.

- [S2] MCP servers with Gemini CLI. Gemini CLI. https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md . License: Apache-2.0. Accessed 2026-11-22.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
