# Tool Definition Repair & Converter for AI Agents (`skilled_glee/capability-contract-repair-bridge`) Actor

An AI tool for agents and developers that repairs broken AI-agent tool definitions and converts between MCP, OpenAI and Anthropic formats, with a change log. Every repaired tool is rechecked with Tool Contract Validator rules. Pure code: no LLM, no network.

- **URL**: https://apify.com/skilled_glee/capability-contract-repair-bridge.md
- **Developed by:** [EchoEmpire Machine Foundry (EchoEmpire LLC)](https://apify.com/skilled_glee) (community)
- **Categories:** Developer tools, AI, Agents
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.50 / 1,000 tool processeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Tool Definition Repair & Converter for AI Agents

Takes AI-agent tool definitions that are broken or in the wrong format and returns fixed, ready-to-use versions plus a log of every change. It is the partner to [Tool Contract Validator for AI Agents](https://apify.com/skilled_glee/tool-contract-validator): that Actor finds the problems, and this one fixes the ones that can be fixed safely without guessing.

Validation and repair are pure code. No LLM, no network, and no proxy. A description or a property is never invented. After each repair, the output is re-checked with the same contract rules as the validator, so a `repaired` result is always valid.

### Input

| Field | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `tools` | array (1–500), or an envelope object | — | yes | Tool definitions. Also accepts an MCP `tools/list` response or `{ "tools": [...] }`. |
| `sourceFormat` | `auto` | `mcp` | `openai` | `anthropic` | `auto` | no | `auto` detects each tool individually. |
| `targetFormat` | `same` | `mcp` | `openai` | `anthropic` | `same` | no | `same` keeps each tool's source format. Otherwise converts the wrapper to MCP (`inputSchema`), OpenAI (`parameters`), or Anthropic (`input_schema`). |
| `mode` | `safe` | `aggressive` | `safe` | no | Safe mode makes only lossless fixes. Aggressive mode also drops required keys that are not defined and removes `$ref`s it cannot resolve. |

If `tools` is missing, not an array (after unwrap), empty, or contains a non-object item, the run fails with a clean input error, writes no dataset items, and charges no events.

#### Input example

This is a broken MCP tool (name with a space, typo `strng`, string `required`, missing root `type`, extra whitespace in the description):

```json
{
  "tools": [
    {
      "name": "get weather",
      "description": " Get current weather. ",
      "inputSchema": {
        "properties": {
          "city": { "type": "strng", "description": "City name" }
        },
        "required": "city"
      }
    }
  ],
  "sourceFormat": "auto",
  "targetFormat": "same",
  "mode": "safe"
}
```

### Output

The dataset has one item per tool plus one summary item. The summary is also stored as the `OUTPUT` record.

Per-tool item:

- `index`, `originalName`, `name`
- `repaired`: the fixed tool definition in the target format, or `null` when status is `failed`
- `changes[]`: `{ "code", "path", "before", "after" }`
- `unfixable[]`: `{ "code", "path", "message" }`
- `status`: `unchanged` | `repaired` | `partial` | `failed`

Summary item:

- `type`: `"summary"`
- `toolsProcessed`, `unchanged`, `repaired`, `partial`, `failed`

#### Output example

For the input example above (safe mode, same format):

```json
[
  {
    "index": 0,
    "originalName": "get weather",
    "name": "get_weather",
    "status": "repaired",
    "changes": [
      { "code": "NAME_SANITIZED", "path": "/name", "before": "get weather", "after": "get_weather" },
      { "code": "DESCRIPTION_TRIMMED", "path": "/description", "before": " Get current weather. ", "after": "Get current weather." },
      { "code": "ROOT_TYPE_ADDED", "path": "/inputSchema/type", "before": null, "after": "object" },
      { "code": "TYPE_CORRECTED", "path": "/inputSchema/properties/city/type", "before": "strng", "after": "string" },
      { "code": "REQUIRED_TO_ARRAY", "path": "/inputSchema/required", "before": "city", "after": ["city"] }
    ],
    "unfixable": [],
    "repaired": {
      "name": "get_weather",
      "description": "Get current weather.",
      "inputSchema": {
        "type": "object",
        "properties": {
          "city": { "type": "string", "description": "City name" }
        },
        "required": ["city"]
      }
    }
  },
  {
    "type": "summary",
    "toolsProcessed": 1,
    "unchanged": 0,
    "repaired": 1,
    "partial": 0,
    "failed": 0
  }
]
```

The summary may also include run metadata such as `charged`, `sourceFormat`, `targetFormat`, `mode`, and `durationMs`.

### What is repaired

- Clean up names: replace characters that are not `A–Z`, `a–z`, `0–9`, `_`, or `-` with `_`, cut to 64 characters, and add `_2`, `_3`, and so on to duplicates.
- Fix the wrapper field for the target format (`inputSchema`, `parameters`, or `input_schema`).
- Add a missing root `type: "object"`, and add an empty `properties` object when it is missing.
- Correct common type typos and aliases (`strng` / `str` → `string`, `int` → `integer`, `bool` → `boolean`, `float` / `double` → `number`).
- Turn a string `required` into an array and remove duplicate entries.
- Drop empty `enum` arrays.
- Inline local `$ref`s that resolve.
- Trim whitespace around names and descriptions.
- Never invent a description or a property. Missing ones are reported as unfixable in safe mode (`status` is `partial`).
- After repairing, re-check each output with the same rules as Tool Contract Validator, so a `repaired` result is always valid.

In aggressive mode, undefined required keys are dropped and unresolvable `$ref`s are removed, which can turn a `partial` result into `repaired` when the rest of the contract is valid.

### Pricing

Pay per event: **`tool-processed` at $0.0015** per tool.

It charges **only** for tools whose output passes the recheck: status `unchanged` or `repaired`. There is **no charge** for `partial` or `failed` items, and no charge for runs rejected at input validation.

The Actor's default run size is 256 MB.

### Limits

- 1 to 500 tool definitions per run
- Default timeout 60 seconds, default memory 256 MB

### Privacy

This Actor uses limited permissions. It does not call the network to fetch or execute tools; it only inspects and rewrites the definitions you pass in.

# Actor input Schema

## `tools` (type: `array,object,string,integer,number,boolean`):

Array of 1-500 tool definitions (MCP, OpenAI or Anthropic format). Also accepts an MCP tools/list response ({"result":{"tools":\[...]}}) or {"tools":\[...]}.

## `sourceFormat` (type: `string`):

Format of the input tools. 'auto' detects each tool individually.

## `targetFormat` (type: `string`):

Format of the repaired output. 'same' keeps each tool's source format.

## `mode` (type: `string`):

'safe' makes only lossless fixes. 'aggressive' also drops undefined required keys and removes unresolvable $refs.

## Actor input object example

```json
{
  "tools": [
    {
      "name": "get weather",
      "description": " Get current weather. ",
      "inputSchema": {
        "properties": {
          "city": {
            "type": "strng",
            "description": "City name"
          }
        },
        "required": "city"
      }
    }
  ],
  "sourceFormat": "auto",
  "targetFormat": "same",
  "mode": "safe"
}
```

# Actor output Schema

## `results` (type: `string`):

One item per tool processed, plus one summary item.

## `summary` (type: `string`):

Run summary: toolsProcessed, unchanged, repaired, partial, failed.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "tools": [
        {
            "name": "get weather",
            "description": " Get current weather. ",
            "inputSchema": {
                "properties": {
                    "city": {
                        "type": "strng",
                        "description": "City name"
                    }
                },
                "required": "city"
            }
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("skilled_glee/capability-contract-repair-bridge").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "tools": [{
            "name": "get weather",
            "description": " Get current weather. ",
            "inputSchema": {
                "properties": { "city": {
                        "type": "strng",
                        "description": "City name",
                    } },
                "required": "city",
            },
        }] }

# Run the Actor and wait for it to finish
run = client.actor("skilled_glee/capability-contract-repair-bridge").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "tools": [
    {
      "name": "get weather",
      "description": " Get current weather. ",
      "inputSchema": {
        "properties": {
          "city": {
            "type": "strng",
            "description": "City name"
          }
        },
        "required": "city"
      }
    }
  ]
}' |
apify call skilled_glee/capability-contract-repair-bridge --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,skilled_glee/capability-contract-repair-bridge"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/EEwE7tyWuseE6JDOk/builds/voV438OK6hrWEovR7/openapi.json
