check_environment
Verify ANTHROPIC_API_KEY configuration and review model details, prior-chapter budget, and Storywright version to ensure environment readiness for multi-agent book writing.
Instructions
Verify ANTHROPIC_API_KEY and show model / prior-chapter budget / Storywright version.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/storywright_mcp/workflow.py:88-107 (handler)Core handler function that validates Anthropic API credentials and reports Storywright version, model, and prior-chapter budget settings.
def check_environment() -> str: """Validate Anthropic API env and report Storywright version.""" msg = api_key_problem_message() lines = [ f"**Storywright** v{__version__}\n", ] if msg: lines.append(f"- API: **NOT READY** — {msg}\n") else: lines.append(f"- API credentials: {anthropic_auth_mode()}\n") bu = os.environ.get("ANTHROPIC_BASE_URL", "").strip() if bu: lines.append(f"- ANTHROPIC_BASE_URL: `{bu}`\n") s = get_settings() lines.append(f"- Model: `{s.anthropic_model}`\n") lines.append( f"- Prior chapter budget: max {s.prior_chapters_max_words} words / " f"{s.prior_chapters_max_count} chapters\n" ) return "".join(lines) - src/storywright_mcp/app.py:62-65 (registration)MCP tool decorator registering 'check_environment' as a FastMCP tool, delegating to workflow.check_environment().
@mcp.tool() async def check_environment() -> str: """Verify ANTHROPIC_API_KEY and show model / prior-chapter budget / Storywright version.""" return workflow.check_environment() - src/storywright_mcp/llm.py:14-29 (helper)Helper that checks for Anthropic API credentials (ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN) and returns an error message if missing.
def api_key_problem_message() -> str | None: """Return user-facing error if API cannot run. The Anthropic Python SDK accepts either ``ANTHROPIC_API_KEY`` (``X-Api-Key``) or ``ANTHROPIC_AUTH_TOKEN`` (Bearer). MiniMax's Anthropic-compatible gateway matches what Claude Code uses with ``ANTHROPIC_AUTH_TOKEN`` + ``ANTHROPIC_BASE_URL``. """ has_key = bool(os.environ.get("ANTHROPIC_API_KEY", "").strip()) has_bearer = bool(os.environ.get("ANTHROPIC_AUTH_TOKEN", "").strip()) if not has_key and not has_bearer: return ( "No Anthropic credentials: set ANTHROPIC_API_KEY and/or ANTHROPIC_AUTH_TOKEN " "(MiniMax proxy typically uses ANTHROPIC_AUTH_TOKEN + ANTHROPIC_BASE_URL). " "Configure MCP `env` in Cursor or a `.env` beside the project." ) return None - src/storywright_mcp/llm.py:32-40 (helper)Helper that returns a human-readable label of which auth mode is configured, used directly in check_environment output.
def anthropic_auth_mode() -> str: """Label for check_environment output.""" has_key = bool(os.environ.get("ANTHROPIC_API_KEY", "").strip()) has_bearer = bool(os.environ.get("ANTHROPIC_AUTH_TOKEN", "").strip()) if has_key and has_bearer: return "ANTHROPIC_API_KEY + ANTHROPIC_AUTH_TOKEN" if has_bearer: return "ANTHROPIC_AUTH_TOKEN (Bearer)" return "ANTHROPIC_API_KEY" - src/storywright_mcp/config.py:8-37 (helper)Settings class (Pydantic) providing the anthropic_model and prior_chapter budget values displayed by check_environment.
class Settings(BaseSettings): model_config = SettingsConfigDict( env_prefix="STORYWRIGHT_", env_file=".env", env_nested_delimiter="__", extra="ignore", ) # Projects live under `{projects_root}/book_projects/<slug>/` projects_root: Path = Path.cwd() # Persist last loaded project path here (optional UX) state_dir: Path = Path.home() / ".storywright" # Model id for writer/editor/third-pass API calls (override per deployment) anthropic_model: str = "claude-sonnet-4-20250514" # Prior approved prose budget for writer prompts (controls context size) prior_chapters_max_words: int = 12000 prior_chapters_max_count: int = 8 # Anthropic API transient failures anthropic_max_retries: int = 2 anthropic_retry_delay_seconds: float = 2.0 _settings: Settings | None = None def get_settings() -> Settings: global _settings if _settings is None: _settings = Settings() return _settings