Function: success()
ts
function success(data, compiledStringify?): ToolResponse;Defined in: packages/core/src/core/response.ts:126
Create a success response from text or a JSON-serializable object.
- Strings are returned verbatim (empty strings become
"OK") - Objects are serialized with
JSON.stringify(data, null, 2)
Parameters
| Parameter | Type | Description |
|---|---|---|
data | string | object | A string message or any JSON-serializable object |
compiledStringify? | StringifyFn | - |
Returns
A ToolResponse with isError unset
Example
typescript
// String response
return success('Task completed');
// Object response (pretty-printed JSON)
const project = await db.projects.create({ name: 'Acme' });
return success(project);
// Array response
const users = await db.users.findMany();
return success(users);See
- error for error responses
- toonSuccess for token-optimized array responses