PYPI PACKAGE AUDIT v0.1.0 Gesundes Paket

unstring

Behebung von MCP-Toolaufrufen, die mit „erwartetes Array, empfangene Zeichenfolge“ fehlschlagen: Repariert Toolaufrufargumente, die Clients und Modelle als JSON-Strings (Arrays, Objekte, Zahlen, boolesche Werte) senden, gesteuert durch das

PyPkgScore unstring
Methodik & Kriterien ♥ Donate
670 / 1000
Schnellinstallation
pip install unstring
1. Governance
50/200
2. PEP-Metadaten
200/200
3. Sicherheit
150/200
4. Doku & SEO
105/200
5. CI-Engineering
165/200
📣 Prüfung teilen: Teilen Sie diesen Bericht und die Vorschau in der aktuellen Sprache
Advertisement
PYPI-TELEMETRIE

Downloads & Community-Verbreitung

Letzte 30 Tage (ohne Spiegelserver)
Letzte 7 Tage
113
Letzte 30 Tage
113
Gesamt (180 Tage)
113
Metrik / Ökosystem Status / Wert Quelle
Downloads (30d / 180d) — PyPI Stats (without mirrors)
Trusted Publishing (PEP 740) ✕ Not detected PyPI Integrity / Sigstore
Django Packages — djangopackages.org
PyTech / PyPkgScore 670 / 1000 PyPkgScore Engine

Gesundheits- & Engineering-Analyse (5 Säulen)

1. Governance & Community50 / 200 ▾
LICENSE✓ 50 pts
SECURITY.md✕ 0 pts
CONTRIBUTING.md✕ 0 pts
CODE_OF_CONDUCT.md✕ 0 pts
2. PEP-Metadaten & Paketierung200 / 200 ▾
Wheel (.whl)✓ 50 pts
pyproject.toml✓ 50 pts
Project URLs✓ 50 pts
Trove Classifiers✓ 50 pts
3. Sicherheit & Lieferkette150 / 200 ▾
Null CVEs (OSV)✓ 60 pts
Trusted Publishing (OIDC)✕ 0 pts
Snyk / Audit Link✓ 40 pts
HTTPS-Repository✓ 50 pts
4. Dokumentation, SEO & Ökosystem105 / 200 ▾
Strukturierte README✓ 60 pts
Read the Docs✕ 0 pts
Django Packages✕ 0 pts
Webseite / Fachartikel✓ 45 pts
5. Engineering, CI & Qualität165 / 200 ▾
Automatisierte Tests✓ 65 pts
GitHub Actions CI✓ 65 pts
CHANGELOG.md✓ 35 pts
Env & Lockfile (uv/rye/poetry/pdm/hatch)✕ 0 pts
Advertisement
README & DOCS

Offizielle Dokumentation & Nutzungsleitfaden — unstring

PyPI Metadata v0.1.0
Vollständige Originaldokumentation anzeigen (Englisches README) ▾

unstring

Some MCP clients and models send tool arguments as JSON strings: "pages": "[{\"title\": \"A\"}]" where the tool's schema says array, "limit": "5" where it says integer. The server rejects the call with expected array, received string (or Input should be a valid list), and the agent retries, gives up, or writes nothing.

unstring repairs those arguments before the server sees them, guided by the tool's own inputSchema. A value is decoded only where the schema does not allow a string, and only when the decoded value has a type the schema does allow, so real strings are never touched. Use it as a stdio proxy around any MCP server (no code changes, any language) or as one function.

pip install unstring

Quick start: any stdio server

Put unstring proxy -- in front of the server command in your client's config:

{
  "mcpServers": {
    "notion": {
      "command": "unstring",
      "args": ["proxy", "--", "npx", "-y", "@notionhq/notion-mcp-server"]
    }
  }
}

Or with uvx, nothing to install first: "command": "uvx", "args": ["unstring", "proxy", "--", ...].

Each repair is reported on stderr (most clients show it in their MCP log):

unstring: create_pages: pages: string -> array; pages[0].position: string -> integer

Proxy options

Option What it does
--wrap Also turn a single value into a one-item list where the schema wants an array ("ids": 4 becomes [4]). Off by default.
--quiet Don't report repairs.
--log FILE Append repair reports to a file instead of stderr.

The proxy learns each tool's schema from the tools/list results the client asks for. If a call names a tool it has not seen (the client cached the list), it asks the server for the tool list itself, holds the call until the answer is in, and then sends it on, repaired. All other messages pass through byte for byte.

In your own server or client: one function

from unstring import repair

schema = {
    "type": "object",
    "properties": {
        "pages": {"type": "array", "items": {"type": "object", "properties": {
            "title": {"type": "string"}, "position": {"type": "integer"}}}},
        "query": {"type": "string"},
        "limit": {"anyOf": [{"type": "integer"}, {"type": "null"}]},
    },
}
result = repair({"pages": '[{"title": "A", "position": "2"}]', "query": "[1, 2]",
                 "limit": "10"}, schema)

print(result.value)
# {'pages': [{'title': 'A', 'position': 2}], 'query': '[1, 2]', 'limit': 10}
print([str(f) for f in result.fixes])
# ['pages: string -> array', 'pages[0].position: string -> integer', 'limit: string -> integer']

query stays a string: the schema says it is one. repair_arguments(args, schema) returns only the value. Check one call from the command line:

$ unstring fix --schema tools.json --tool create_pages '{"pages": "[{\"title\": \"A\"}]"}'
repaired pages: string -> array
{
  "pages": [
    {
      "title": "A"
    }
  ]
}

--schema takes an inputSchema, a tool, or a saved tools/list result. The exit code is 2 when something was repaired, 0 when nothing needed it.

What gets repaired

  • JSON text for arrays, objects, integers, numbers, booleans and null where the schema wants those types, at any depth: inside arrays, nested objects, $ref/$defs, anyOf/oneOf/ allOf, additionalProperties, patternProperties, prefixItems.
  • Double-encoded JSON ("\"[1, 2]\"").
  • Python literals some bridges send ("['a', 'b']", "{'k': True}"), parsed safely with ast.literal_eval, never eval.
  • Arrays that arrived as index-keyed objects ({"0": x, "1": y} where the schema wants an array), as some HTTP bridges send them.
  • "True"/"FALSE" for booleans, "5.0" for an integer field.
  • The whole arguments object sent as one JSON string.

Limits

  • Where the schema allows a string ("type": ["string", "array"], an untyped field, {}), the string is left alone, because there is no safe way to tell. Give the field a type if you want it repaired.
  • unstring proxy works with stdio servers. For a remote (Streamable HTTP) server, call repair in the server where the arguments arrive.
  • It fixes types, not values: a wrong enum, a missing required field or a bad date still reaches the server and fails there, as it should.
  • Strings like "007" or "1,2" are not valid JSON and are not guessed at.

Why this exists

Clients keep sending stringified arguments, intermittently, and every server works around it on its own (tryParseJson helpers, z.preprocess, accept-a-string-too unions):

License

MIT