Skip to content

[BUG][API]: Selective export crashes with AttributeError on Tool.rate_limit #2916

@crivetimihai

Description

@crivetimihai

Description

The selective export endpoint POST /export/selective crashes with a 500 Internal Server Error when exporting tools. The error is:

Export failed: 'Tool' object has no attribute 'rate_limit'

Root Cause

In mcpgateway/services/export_service.py, the _export_selected_tools() method (line ~813) accesses db_tool.rate_limit and db_tool.timeout directly:

"rate_limit": db_tool.rate_limit,
"timeout": db_tool.timeout,

However, the Tool ORM model in mcpgateway/db.py (line ~2738) does not define rate_limit or timeout columns. This causes an AttributeError.

The full export path (_export_tool_data, line ~429) correctly uses getattr() with a fallback:

"rate_limit": getattr(tool, "rate_limit", None),
"timeout": getattr(tool, "timeout", None),

This is a copy-paste inconsistency between the two code paths.

Steps to Reproduce

# Create a tool
curl -X POST http://localhost:8080/tools/ \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"tool": {"name": "test-tool", "url": "https://httpbin.org/post", "integration_type": "REST", "request_type": "POST"}, "team_id": null}'

# Try selective export (returns 500)
curl -X POST http://localhost:8080/export/selective \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"tools": ["<tool_id>"]}'

Expected Behavior

Selective export should return the exported tool data (same as full export).

Suggested Fix

In mcpgateway/services/export_service.py, change _export_selected_tools() lines ~813-814 from:

"rate_limit": db_tool.rate_limit,
"timeout": db_tool.timeout,

to:

"rate_limit": getattr(db_tool, "rate_limit", None),
"timeout": getattr(db_tool, "timeout", None),

This matches the pattern already used in _export_tool_data().

Environment

Metadata

Metadata

Assignees

Labels

SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releaseapiREST API Related itembugSomething isn't working

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions