Imported from zizzfizzix/mcp-server-bwt (
AGENTS.md). Install upstream withnpx skills add zizzfizzix/mcp-server-bwt. Copyright stays with the author.
AGENTS.md
Project overview
mcp-server-bwt is a Python MCP (Model Context Protocol) server that connects AI assistants to the Bing Webmaster Tools API. It runs over stdio (MCPServer from mcp[cli] 2.x) and exposes the service methods of the bing-webmaster-tools client library as MCP tools. There are 62 today, covering site management, submission, traffic, crawling, keywords, links, content, blocking, regional settings and URL parameters. It is packaged with hatchling, managed with uv, and published to PyPI as mcp-server-bwt. Users launch its mcp-server-bwt console script through uvx mcp-server-bwt. It supports Python 3.13 and newer. Development and CI run on the 3.14 release pinned in .python-version.
Task routing
| When the task involves… | Read first | Key rules |
|---|---|---|
| Server startup, env config, entry point | mcp_server_bwt/main.py, pyproject.toml ([project.scripts]) |
BING_WEBMASTER_API_KEY is read at import time and a missing value raises ValueError. app() is the console-script target and must keep transport="stdio". Never log or echo the API key. |
| Adding, removing or renaming an MCP tool | mcp_server_bwt/tools/bing_webmaster.py, README.md (## Available Tools) |
Register tools only through wrap_service_method(mcp, service, "<service_attr>", "<method>") and assign the result to a variable named after the method with # noqa: F841. Keep tools grouped under the # <Area> Tools comments. Tool names, signatures and docstrings come from the upstream library method, so don't hand-write them. Update the README tool list in the same PR. Renaming or removing a tool is a breaking change (see BACKWARD_COMPATIBILITY.md). wrap_service_method adds offset/limit paging to every tool whose upstream method is annotated to return a list, and it raises if the upstream method already has either name. Default page size: BING_WEBMASTER_PAGE_SIZE, else 50 (max 500; 0 disables). Each list tool also caches its upstream list, keyed on the arguments minus offset/limit, in its own ResultCache for BING_WEBMASTER_CACHE_TTL seconds, else 300 (0 disables; errors are never cached). Every non-list tool whose name doesn't start with get_ counts as a write and clears all list caches of its service_attr area when it runs, even if it fails. sites writes clear every area (GLOBAL_WRITE_AREA). A new read tool must therefore be named get_…, or it will clear caches needlessly (test_write_tools_are_exactly_the_mutating_tools pins the set). Tests that share main.mcp must disable cache hits (see test_startup.py). Paged results come back as a CallToolResult, and mcp re-validates their dumped rows against the output model, so every model field must survive a JSON round trip. That's why the date parser in services/bing_webmaster.py accepts RFC 3339. |
| A new upstream service area | mcp_server_bwt/tools/bing_webmaster.py (SERVICE_CLASSES), mcp_server_bwt/services/bing_webmaster.py (__aenter__) |
Add the service class to SERVICE_CLASSES and instantiate it on the same attribute name in BingWebmasterService.__aenter__. The two maps must stay in sync. |
| API client settings (timeouts, retries, rate limits, base URL) | mcp_server_bwt/services/bing_webmaster.py |
Settings are built in BingWebmasterService.__init__. The key is wrapped in pydantic.SecretStr. Each tool call opens and closes the client through async with service. disable_destructive_operations=False is deliberate, so destructive tools (remove site, remove feed, …) are exposed. |
| Dependencies and packaging | pyproject.toml, mcp_server_bwt/version.py |
uv.lock is committed, so installs are reproducible. Change dependencies in pyproject.toml, then run uv lock and commit both files. mcp[cli] is pinned to >=2.2,<3. The server uses mcp.server.mcpserver.MCPServer, because mcp 2.x removed mcp.server.fastmcp (#8, #14). The next major needs the same schema diff as this one did. The version is sourced from mcp_server_bwt/version.py (__VERSION__) via [tool.hatch.version]. Add dev tools to [dependency-groups].dev (this includes lefthook, whose PyPI package ships the hook binary). requires-python is >=3.13, while .python-version pins 3.14 for development and CI, so CI never runs 3.13. [tool.mypy] python_version stays at the requires-python floor, and ruff infers its target from it, so both still check the code against 3.13. What gets published is set in pyproject.toml: the sdist include list (the package, README.md, LICENSE, CHANGELOG.md, pyproject.toml) and the wheel exclude of mcp_server_bwt/test_*.py. Keep repo process files out of both. The README is the PyPI project description, so use absolute URLs for links. PyPI versions are immutable: a bad release is yanked and fixed forward, never re-uploaded. |
| Tests | pyproject.toml ([tool.pytest.ini_options]), Makefile (test) |
Tests live next to the code as mcp_server_bwt/test_*.py (for example test_startup.py). pytest runs over mcp_server_bwt with --doctest-modules, and pythonpath = "mcp_server_bwt". mypy excludes files matching .+test_. Collection imports main.py, which reads the API key at import time, so run the tests with a dummy key: BING_WEBMASTER_API_KEY=dummy make test. The suite also runs in the validation gate, in CI, and in the lefthook pre-push hook, always with a fixed dummy key. |
| Tooling, lint, types, git hooks | Makefile, pyproject.toml ([tool.mypy]), lefthook.yml |
Code must pass mypy --strict and ruff (lint and format, default config). Every function carries full type annotations. Use # type: ignore only where the dynamic wrapping genuinely requires it. make install installs lefthook git hooks. pre-commit runs ruff check --fix and ruff format on staged *.py files and restages the fixes. pre-push runs, in parallel, mypy --strict, the gate's pytest command (with BING_WEBMASTER_API_KEY=dummy) when *.py files are pushed, and uv lock --check when pyproject.toml or uv.lock is pushed. Skip them with --no-verify or LEFTHOOK=0. The hooks don't replace the validation gate below. In a hook sub-job that fixes files, set stage_fixed: true on the sub-job itself, not on its group. |
| Releases | release-please-config.json, .release-please-manifest.json, .github/workflows/release-please.yml |
release-please owns the version: it keeps a chore(main): release X.Y.Z PR open, and merging that PR bumps mcp_server_bwt/version.py, updates CHANGELOG.md, tags vX.Y.Z, and publishes a GitHub release. Never hand-edit __VERSION__ (its line carries # x-release-please-version), CHANGELOG.md, or the manifest. The squash-merged PR title decides the bump: fix: → patch, feat: → minor, and a breaking change (feat!: or a BREAKING CHANGE: footer) → minor while pre-1.0. chore:/docs:/refactor: don't release. The same workflow publishes each new release to PyPI. The build job checks out the tag, runs uv build and fails unless the built version matches the tag. The publish job uploads through PyPI Trusted Publishing (OIDC) in the pypi environment, which only accepts deployments from main. Never add a PyPI token secret. The PyPI publisher is bound to the workflow filename release-please.yml and the environment name pypi, so renaming either breaks uploads until PyPI is updated. To backfill a tag or retry a failed upload, run gh workflow run release-please.yml -f tag=vX.Y.Z from main (the pypi environment rejects any other ref). |
| CI | .github/workflows/ci.yml, .github/workflows/release-please.yml |
ci.yml has one job, validate, which runs on every PR and on every push to main. It runs uv sync --locked, the validation-gate commands below as separate steps in the same order (the pytest step, Tests, sets the dummy key through env:), and an import smoke test (BING_WEBMASTER_API_KEY=dummy uv run python -c "import mcp_server_bwt.main"). validate is a required status check on the main ruleset (bound to the GitHub Actions app), so a PR can't merge until it passes. Never rename the job, because the required check matches it by name. Release-please PRs are the one exemption. A job-level if: skips validate when the PR's head is in this repository and its head branch starts with release-please--branches--. The skipped job still reports validate, which satisfies the required check. Those PRs only touch generated release files, and main re-validates after they merge. Fork PRs, other PRs, and pushes to main always run the full gate. The workflow steps mirror validation.commands in .ai/agentic.config.json, so change them together. There are no paths: filters, because a required check has to report on every PR. release-please.yml runs on push to main (plus a manual workflow_dispatch with a tag input for PyPI backfills). It opens release PRs with the RELEASE_PLEASE_TOKEN repo secret, and its build/publish jobs upload each release to PyPI (see Releases). Permissions are per job, and id-token: write is granted only to publish. That secret has to stay set: PRs opened with the default token don't trigger validate, and a release PR without it can't merge. |
| Docs | README.md |
The README documents client setup from PyPI via uvx mcp-server-bwt (Claude Desktop, Claude Code, Cursor, Zed), upgrades and pinning, a contributor-only local-checkout setup under Development, and the full tool list. Never document a git+https:// install. test_packaging.py enforces the uvx configs and the absence of git installs. Keep both accurate when behavior changes. |
Validation gate
Run in order. Any non-zero exit fails the gate:
uv run ruff check mcp_server_bwt/uv run ruff format --check mcp_server_bwt/uv run mypy --strict mcp_server_bwt/uv buildBING_WEBMASTER_API_KEY=dummy uv run pytest mcp_server_bwt --doctest-modules
Use make format or uv run ruff check --fix to fix drift locally. make lint runs ruff --fix and changes files, so it isn't used as the gate.
Pointers
- Delivery process, labels, claim protocol:
SDLC.md - Review rules:
CODE_REVIEW.md - Protected contract surfaces:
BACKWARD_COMPATIBILITY.md - Pipeline config:
.ai/agentic.config.json(tracker descriptor in.ai/trackers/github.md)
