<type>how-to</type>
<domain>install</domain>
<id>claude-code</id>
<title>Using Wing Pro with Claude Code</title>
<date>$Date$</date>
<product>pro+</product>
<summary>Learn how to set up Claude Code to work with Wing Pro via MCP.</summary>

`Wing Pro <https://wingware.com>`__ can be used together with
`Claude Code <https://claude.ai/code>`__ via the
`Model Context Protocol <https://modelcontextprotocol.io/>`__ (MCP). This gives Claude Code
access to Wing features such as the test runner, allowing it to run tests, analyze code
coverage, and more.

This document describes how to configure Claude Code to work with Wing.

Quick Setup with New Project
----------------------------

The easiest way to set up Claude Code is when creating a new Wing project:

1. Use ``New Project`` in the ``Project`` menu
2. Select your host, source directory, and project type as usual
3. Check the **Set Up for Claude Code** option
4. Complete the project creation

Wing will write an ``.mcp.json`` file in your project source directory. The next time
Claude Code is started in that directory, it will automatically discover Wing's MCP servers
and make their tools available.

.. note::

  The ``.mcp.json`` file specifies the path to the Wing project file (``.wpr``) for the
  testing MCP server. The ``.wpr`` file is used to determine the test framework, Python
  executable, test file locations, and other project settings. When using the New Project
  dialog, this is set up automatically.

Testing and Coverage with Claude Code
---------------------------------------

Claude Code also has access to Wing's test runner and coverage analysis. You can ask Claude
Code to:

* **Discover tests** -- "List all test files in this project"
* **Run tests** -- "Run the tests" or "Run test_foo.py"
* **Run tests with coverage** -- "Run tests with coverage collection"
* **Find affected tests** -- "Which tests are affected by my changes to utils.py?"
* **Get coverage info** -- "Show coverage for src/mymodule.py"

The testing MCP server reads the Wing project file (``.wpr``) to determine which test
framework to use (pytest, unittest, etc.), how to discover test files (via the
``testing.auto-test-file-specs`` and ``testing.test-file-list`` project attributes), and which
Python interpreter to run tests with.

**Coverage-based test invalidation:** When tests are run with coverage collection (the
default), the server tracks which test functions execute which lines of source code. After
making code changes, you can ask "which tests are affected?" and the server will identify the
exact tests that exercised the changed lines -- not just tests that touched the file, but tests
that ran the specific lines you changed. This is especially useful in large codebases where
running all tests would take a long time.

The testing MCP server runs as a separate process and does not require the Wing IDE to be open.

Troubleshooting
---------------

**MCP server fails to start:** Verify that the path in ``.mcp.json`` points to an existing
Wing installation. If you have reinstalled or moved Wing, update the path accordingly.

**Python not found:** The MCP servers use Wing's bundled Python interpreter. If this fails,
ensure your Wing installation is complete by running ``wing --check-install`` from the
command line.

**Path changes after update:** After updating Wing to a new version, you may need to update
the path in ``.mcp.json`` if the installation directory has changed. Creating a new project
with the **Set Up for Claude Code** option will always write the correct path.

**No project file found:** The testing MCP server requires a Wing project file (``.wpr``).
The path to the ``.wpr`` file should be specified via the ``--wpr`` argument in ``.mcp.json``.
If you used the New Project dialog, this is set up automatically. For manual setup, see
the Manual Setup section below.

**No coverage data:** If coverage queries return no data, make sure you have run tests with
coverage collection enabled first. The ``test_run`` tool collects coverage by default.

Manual Setup
------------

If you prefer to configure Claude Code manually instead of using the New Project dialog,
create a file named ``.mcp.json`` in the root of your project directory with the following
content:

**Linux and macOS:**

.. code-block:: json

  {
    "mcpServers": {
      "wing-testing": {
        "command": "/path/to/wing/bootstrap/run-mcp-testing.sh",
        "args": ["--wpr", "myproject.wpr"]
      }
    }
  }

**Windows:**

.. code-block:: json

  {
    "mcpServers": {
      "wing-testing": {
        "command": "C:\\path\\to\\wing\\bootstrap\\run-mcp-testing.bat",
        "args": ["--wpr", "myproject.wpr"]
      }
    }
  }

Replace the command paths with the actual path to your Wing installation directory, and
``myproject.wpr`` with the path to your Wing project file (relative to the ``.mcp.json``
location, or an absolute path).

~~~if not WEBSITE:
The Wing installation directory can be found by looking at the ``About`` dialog in
Wing's ``Help`` menu.
~~~
