Skip to main content

Shared utilities for mrlesmithjr MCP servers: logging, config, paths, errors

Project description

mrlesmithjr-mcp-common

Shared building blocks for FastMCP servers: stderr-safe logging, layered configuration, XDG path resolution, and a consistent JSON error envelope. It is the common foundation under the mrlesmithjr/mcp tool suite, but has no dependency on those tools and is usable in any MCP server.

Import as mcp_common.

Install

pip install mrlesmithjr-mcp-common
# or
uv add mrlesmithjr-mcp-common

Usage

import json
from mcp_common.server import build_server, run_stdio
from mcp_common.errors import safe_tool

mcp = build_server("my-tool", instructions="What this server does.")

@mcp.tool()
@safe_tool
def do_thing(x: str) -> str:
    return json.dumps({"status": "ok", "data": x})

def main() -> None:
    run_stdio(mcp)

safe_tool wraps a tool so unhandled exceptions return a structured {"error": ...} envelope instead of crashing the server. build_server and run_stdio handle FastMCP setup and stdio transport; configure_logging() forces logs to stderr (stdout is reserved for the protocol).

Modules

Module Purpose
mcp_common.logging configure_logging() forcing stderr output (required for stdio transport)
mcp_common.server build_server(name, instructions) and run_stdio(mcp)
mcp_common.config load_layered_config(tool_name, env_map): env vars > config.json > .env fallback
mcp_common.paths config_dir(), config_file(), data_dir() XDG path resolvers
mcp_common.errors tool_error(), error_json(), safe_tool decorator
mcp_common.coordinator_events emit_coordinator_event(source, event_type, payload) -> bool: self-healing write onto homeops-coordinator's events.db bus. Never raises; returns False on failure so callers can fire-and-forget it after a state change.
mcp_common.google_oauth GoogleOAuthClient: shared Google OAuth2 base class (token storage/refresh, authenticated request()) for any tool calling a Google REST API. Credentials at ~/.config/google/credentials.json (shared across tools); tokens per-tool at ~/.config/<tool_name>/<token_filename>. Used by apple-eventkit-tools' GoogleCalendarClient (issue #59) and contacts-tools' GooglePeopleClient (issue #60).

Requirements

  • Python 3.11+

License

MIT. Part of the mrlesmithjr/mcp workspace.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mrlesmithjr_mcp_common-0.1.2.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mrlesmithjr_mcp_common-0.1.2-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file mrlesmithjr_mcp_common-0.1.2.tar.gz.

File metadata

  • Download URL: mrlesmithjr_mcp_common-0.1.2.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mrlesmithjr_mcp_common-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c0480fb5889c380d1e5774f7254463ca75e5cbf79d89bf81c610650cf79c040a
MD5 e6e7d7f412cce6edfe4cd677d5b49e41
BLAKE2b-256 709b056da8137ee9b94ba8c187436f16b60eaa786b95d4176de3091d11f7b7ac

See more details on using hashes here.

File details

Details for the file mrlesmithjr_mcp_common-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mrlesmithjr_mcp_common-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mrlesmithjr_mcp_common-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 29a56acb26c923cca87e49e337879f0f1a8282af0e0201ebee6b4ca492bdf10e
MD5 4bcfbf77e8ddeab832a6c9885fd681ef
BLAKE2b-256 f4bd6341d3ddd87be1adb0e4fac9cd213a7a909f25220822125023be7e2a67fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page