Metadata-Version: 2.4
Name: tialink-mcp
Version: 0.1.0
Summary: stdio to Streamable HTTP bridge for TiaLink, the TIA Portal MCP gateway by hubwiz.com
Author-email: "hubwiz.com" <service@hubwiz.com>
License-Expression: MIT
Project-URL: Homepage, https://tia.hubwiz.com/tia-link?utm_source=pypi&utm_medium=readme&utm_campaign=tialink-mcp
Project-URL: Repository, https://github.com/tia-forge/tialink
Project-URL: Issues, https://github.com/tia-forge/tialink/issues
Project-URL: Gateway docs, https://tia.hubwiz.com/tia-link
Keywords: mcp,model-context-protocol,mcp-server,mcp-gateway,tia-portal,siemens,plc,scl,openness,industrial-automation,bridge
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Manufacturing
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# tialink-mcp (Python)

**stdio ↔ Streamable HTTP bridge for [TiaLink](https://tia.hubwiz.com/tia-link?utm_source=pypi&utm_medium=readme&utm_campaign=tialink-mcp)** — the TIA Portal MCP gateway by [汇智网 (hubwiz.com)](https://www.hubwiz.com/).

TiaLink serves MCP over **Streamable HTTP** at `http://<gateway-host>:8080/mcp`. Most clients can speak that directly. Some hosts — and every one-click desktop bundle — can only launch a **stdio** server. This package is the adapter between the two: newline-delimited JSON-RPC on stdin, HTTP on the other side, replies written back to stdout.

```text
MCP client (stdio only)  ──stdin/stdout──▶  tialink-mcp  ──HTTP──▶  TiaLink gateway (/mcp)
                                                                     └──▶ TIA Portal Openness
```

> ⚠️ **This package is the adapter, not the product.** It needs a licensed TiaLink gateway
> already running on a Windows machine with TIA Portal V17–V21. Without one it fails on the
> first request — by design. It contains no TIA Portal logic and unlocks nothing.

## Install

```bash
uvx tialink-mcp --check                     # one-shot, no install (recommended)
pipx run tialink-mcp --check
pip install tialink-mcp                     # or install it globally
```

Zero runtime dependencies; Python 3.9+.

## Use

MCP clients that can launch a command:

| Field | Value |
|---|---|
| command | `uvx` |
| args | `["tialink-mcp"]` |
| env | `TIALINK_URL` (default `http://127.0.0.1:8080/mcp`), `TIALINK_TOKEN` (only if the gateway was configured with a token) |

`claude_desktop_config.json` / `mcp.json`:

```json
{
  "mcpServers": {
    "tialink": {
      "command": "uvx",
      "args": ["tialink-mcp"],
      "env": { "TIALINK_URL": "http://127.0.0.1:8080/mcp" }
    }
  }
}
```

## Pre-flight check

Before wiring anything into a client, ask the gateway who it is:

```bash
TIALINK_URL=http://192.168.1.78:8080/mcp TIALINK_TOKEN=... tialink-mcp --check
```

```text
✓ gateway reachable
  server      : TiaLink <version>
  protocol    : 2025-06-18
  capabilities: tools, resources
  session id  : <session>
  tools       : 41
    - project.open
    - block.create
    ...
```

If it fails:

| Symptom | Meaning |
|---|---|
| `cannot reach … — Connection refused` | Gateway not running, or wrong host/port. It listens on the machine where TiaLink is installed. |
| `HTTP 401` / `403` | `TIALINK_TOKEN` missing or wrong (header is `Authorization: Bearer <token>`). |
| `HTTP 404` | Wrong path — the endpoint is `/mcp`, not the host root. |
| `did not answer within … ms` | Compile/download/simulation calls can take minutes; raise `TIALINK_TIMEOUT_MS`. |

## Environment variables

| Variable | Default | Purpose |
|---|---|---|
| `TIALINK_URL` | `http://127.0.0.1:8080/mcp` | Gateway endpoint |
| `TIALINK_TOKEN` | *(empty)* | Bearer token, if the gateway requires one |
| `TIALINK_TIMEOUT_MS` | `600000` (10 min) | Per-request timeout |
| `TIALINK_QUIET` | *(unset)* | `1` silences diagnostics on stderr |

stdout carries the MCP protocol only; every diagnostic goes to stderr, so logs can never corrupt the stream.

## Other distributions of the same adapter

| Ecosystem | Install | Notes |
|---|---|---|
| npm | `npx tialink-mcp` | Node ≥ 18, no dependencies |
| Python (this package) | `uvx tialink-mcp` | Python ≥ 3.9, no dependencies |

## Development

```bash
PYTHONPATH=src python -m unittest discover -s tests -v   # 8 end-to-end tests, fake gateway included
PYTHONPATH=src python -m tialink_mcp --help
```

## License

MIT for this bridge and its packaging only — see [`LICENSE`](./LICENSE).
The TiaLink engine is commercial software and is not covered by that licence.
TiaLink is not affiliated with or endorsed by Siemens.
