Skip to main content

Resource Out

Returns the content of a resource to the MCP client. This node completes the resource retrieval flow by sending the requested resource data back to the requesting client.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Caller ID - Unique identifier for the resource request. This is automatically provided by the system and matches the request to its response channel.
  • Resource URI - The URI of the resource being returned. Should match the requested URI.
  • Content Type - The MIME type of the resource content. Examples: text/plain, application/json, text/markdown.
  • Resource Data - The actual content of the resource as a string. This is what the client receives.

How It Works

The Resource Out node completes the resource retrieval workflow:

  1. Request Tracking - Receives the Caller ID that identifies the specific client request
  2. Channel Lookup - Finds the response channel associated with this request
  3. Data Validation - Validates the Resource URI, Content Type, and Resource Data
  4. Content Type Handling - Uses provided Content Type or defaults to text/plain
  5. Response Creation - Creates an MCP-compliant resource result with the content
  6. Client Delivery - Sends the result back to the waiting client through the response channel

The node creates a structured resource response with:

  • Resource URI (identifies what was requested)
  • MIME type (describes content format)
  • Text content (the actual resource data)

Requirements

  • Must receive a valid Caller ID from the message context
  • Resource URI should be provided (identifies the resource)
  • Content Type is optional (defaults to text/plain)
  • Resource Data must be a string
  • Must be used after a Resource In node in the flow

Error Handling

The node returns errors in the following cases:

  • Failed to get caller ID - Caller ID is missing from the message
  • No result channel found - Response channel doesn't exist for the Caller ID
  • Failed to get resource URI/data - Required inputs are missing
  • Any errors are wrapped with descriptive messages for debugging

Usage Notes

Flow Structure

A typical resource flow structure:

  1. Listen node (with Resource In connected to resources port)
  2. Resource In node (receives request with URI and parameters)
  3. Data fetching/generation logic
  4. Resource Out node (sends response)

Content Format

  • Resource Data must be a string
  • If your data is an object, convert it to JSON string
  • For binary data, encode as base64 string
  • Ensure content matches the declared Content Type

Content Type Defaults

  • If Content Type is not provided or empty, defaults to text/plain
  • Always specify Content Type when returning structured data
  • Match Content Type to actual data format

Examples

Example 1: Return Text File

Resource In receives: docs://readme

Processing:

  1. Read README.md file from disk
  2. Load content as string

Resource Out inputs:

  • Caller ID: (from message)
  • Resource URI: docs://readme
  • Content Type: text/markdown
  • Resource Data: (README file content)

Client receives: Markdown content of README


Example 2: Return JSON Data

Resource In receives: users://123/profile

Processing:

  1. Query database for user ID 123
  2. Format as JSON string

Resource Out inputs:

  • Caller ID: (from message)
  • Resource URI: users://123/profile
  • Content Type: application/json
  • Resource Data: {"id": 123, "name": "Alice", "email": "alice@example.com"}

Client receives: JSON user profile


Example 3: Return Generated CSV

Resource In receives: reports://2024/03/sales

Processing:

  1. Query sales database
  2. Generate CSV format
  3. Convert to string

Resource Out inputs:

  • Caller ID: (from message)
  • Resource URI: reports://2024/03/sales
  • Content Type: text/csv
  • Resource Data:
Date,Product,Amount
2024-03-01,Widget A,1200
2024-03-02,Widget B,850

Client receives: CSV sales report


Example 4: Return HTML Page

Resource In receives: pages://help/getting-started

Processing:

  1. Load HTML template
  2. Insert dynamic content
  3. Return complete HTML

Resource Out inputs:

  • Caller ID: (from message)
  • Resource URI: pages://help/getting-started
  • Content Type: text/html
  • Resource Data: Complete HTML page as string

Example 5: Error Response

Resource In receives: users://999/profile

Processing:

  1. Query database
  2. User not found
  3. Generate error message

Resource Out inputs:

  • Caller ID: (from message)
  • Resource URI: users://999/profile
  • Content Type: application/json
  • Resource Data: {"error": "User not found", "code": 404}

Note: Even error responses go through Resource Out to ensure client receives a response.

Best Practices

  1. Always Respond:

    • Every Resource In should have a corresponding Resource Out
    • Always send a response, even for errors
    • Don't leave clients waiting indefinitely
  2. Accurate Content Types:

    • Always specify the correct MIME type
    • Match Content Type to actual data format
    • Use standard MIME types
  3. Data Validation:

    • Validate Resource Data before sending
    • Ensure data is properly formatted
    • Check that data is a string
  4. URI Consistency:

    • Resource URI should match what was requested
    • Include all path parameters
    • Maintain URI structure
  5. Error Handling:

    • Return structured error messages
    • Include helpful error details
    • Use appropriate error formats (JSON for JSON resources)
  6. Performance:

    • Minimize processing time before Resource Out
    • Use efficient data serialization
    • Consider caching for frequently accessed resources
  7. String Conversion:

    • Convert objects to JSON strings: JSON.stringify(obj)
    • Ensure proper encoding for special characters
    • Handle null/undefined values

Common Errors and Solutions

Error: "Failed to get caller ID"

Cause: Caller ID is missing from the message context.

Solution:

  • Ensure Resource Out is connected after Resource In
  • Check message context is passed through the flow
  • Verify no nodes clear the message context

Error: "No result channel found for caller ID"

Cause: Response channel no longer exists.

Solution:

  • Client may have timed out
  • Reduce processing time before Resource Out
  • Check for excessive delays in the flow

Error: "Failed to get resource URI"

Cause: Resource URI input is missing.

Solution:

  • Connect Resource URI input
  • Ensure URI is provided from Resource In or processing logic
  • Check for null/undefined values

Error: "Failed to get resource data"

Cause: Resource Data input is missing or empty.

Solution:

  • Ensure data fetching logic completed successfully
  • Check for errors in data processing nodes
  • Verify Resource Data input is connected

Tips for Effective Use

  1. Caller ID Handling - Pass Caller ID through processing nodes unchanged
  2. String Conversion - Always convert data to string before Resource Out
  3. Content Type Accuracy - Match Content Type to actual data format
  4. Fast Response - Process and respond quickly to avoid timeouts
  5. Error Responses - Send structured error messages instead of failing
  6. Logging - Log responses for debugging and monitoring
  7. Testing - Test with various resource types and formats

Integration Patterns

Pattern 1: Simple File Return

Resource In → Read File → Resource Out

Direct file content return.

Pattern 2: Database Query

Resource In → Validate → Query DB → Format → Resource Out

Fetch and return database records.

Pattern 3: API Proxy

Resource In → Call External API → Transform → Resource Out

Proxy external API data.

Pattern 4: Generated Content

Resource In → Fetch Data → Generate Document → Resource Out

Dynamically generate resource content.

Pattern 5: Error Handling

Resource In → Try → Fetch Data → Resource Out

Catch → Error Message → Resource Out

Handle errors with proper responses.

Pattern 6: Multi-Format Support

Resource In → Fetch Data → Format Switch → Resource Out
├─ JSON
├─ CSV
└─ XML

Return data in requested format based on parameters.

Data Format Examples

JSON Resource

// Convert object to JSON string
const data = { id: 123, name: "Alice" };
const resourceData = JSON.stringify(data);
// Content Type: "application/json"

CSV Resource

// Build CSV string
const rows = [
["Name", "Age", "City"],
["Alice", "30", "NYC"],
["Bob", "25", "LA"]
];
const resourceData = rows.map(row => row.join(",")).join("\n");
// Content Type: "text/csv"

Markdown Resource

// Build markdown string
const resourceData = `# Title\n\nContent here with **bold** text.`;
// Content Type: "text/markdown"

XML Resource

// Build XML string
const resourceData = `<?xml version="1.0"?><data><item>value</item></data>`;
// Content Type: "application/xml"