Skip to main content

Read Resource

Reads the content of a resource from an MCP server. This node retrieves resource data (files, documents, API responses, etc.) from connected MCP servers.

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.

Inputs

  • Client Id - The MCP client connection identifier from the Connect node.
  • Resource URI - The URI of the resource to retrieve (e.g., docs://readme, users://123/profile).

Options

  • Timeout - Timeout in seconds for the operation (default: 30).

Outputs

  • Content - The resource content. If the content is JSON, it's parsed to an object; otherwise, returned as a string.
  • MIME Type - The MIME type of the resource (e.g., text/plain, application/json, text/markdown).

How It Works

The Read Resource node retrieves resource content from MCP servers:

  1. Client Lookup - Retrieves the MCP client using the provided Client ID
  2. Request Creation - Creates an MCP ReadResourceRequest with the URI
  3. Resource Reading - Sends request to server and receives resource data
  4. Content Processing - Extracts content based on type (text or blob)
  5. JSON Parsing - If content looks like JSON, parses it to an object
  6. Output - Returns content and MIME type

Content Type Handling

The node intelligently processes different content types:

  • Text Resources - Returned as strings
  • JSON Resources - Automatically parsed to objects
  • Binary Resources - Returned as base64-encoded strings
  • Unknown Types - Returned as strings

Requirements

  • Valid Client ID from a Connect node
  • Non-empty Resource URI
  • Active connection to the MCP server
  • Resource must exist on the server

Error Handling

The node returns specific errors:

  • ErrInvalidArg - Client ID or Resource URI is empty
  • ErrMCPToolCall - Failed to read the resource from the server

Usage Notes

URI Format

  • Static URIs: docs://readme - Access a specific resource
  • Template URIs: users://123/profile - Access with parameters (replace {id} with actual value)
  • Scheme-based: Use appropriate scheme prefix (docs://, api://, users://, etc.)

Content Output

  • Text content is returned as-is
  • JSON content is automatically parsed to an object
  • Binary content is base64-encoded
  • Empty resources return null content with text/plain MIME type

Examples

Example 1: Read Text File

Inputs:

  • Client Id: file-server
  • Resource URI: docs://readme

Outputs:

  • Content: "# Project Documentation\n\nWelcome to the project..."
  • MIME Type: text/markdown

Example 2: Read JSON Data

Inputs:

  • Client Id: api-server
  • Resource URI: users://123/profile

Outputs:

  • Content:
{
"id": 123,
"name": "Alice Smith",
"email": "alice@example.com",
"role": "admin"
}
  • MIME Type: application/json

Example 3: Read Configuration

Inputs:

  • Client Id: config-server
  • Resource URI: config://app-settings

Outputs:

  • Content:
{
"theme": "dark",
"language": "en",
"notifications": true,
"apiUrl": "https://api.example.com"
}
  • MIME Type: application/json

Example 4: Read CSV Data

Inputs:

  • Client Id: data-server
  • Resource URI: reports://2024/sales.csv

Outputs:

  • Content:
Date,Product,Amount
2024-01-01,Widget A,1200
2024-01-02,Widget B,850
  • MIME Type: text/csv

Processing:

// Parse CSV in JavaScript node
const lines = msg.content.split('\n');
const headers = lines[0].split(',');
const data = lines.slice(1).map(line => {
const values = line.split(',');
const obj = {};
headers.forEach((header, i) => {
obj[header] = values[i];
});
return obj;
});
msg.parsed_csv = data;

Example 5: Templated Resource

Inputs:

  • Client Id: db-server
  • Resource URI: products://electronics/laptops

Outputs:

  • Content: (Array of products)
[
{"id": 1, "name": "Laptop Pro", "price": 1299},
{"id": 2, "name": "Laptop Air", "price": 999}
]
  • MIME Type: application/json

Best Practices

  1. URI Validation:

    • Use List Resources first to discover available URIs
    • Verify URI format is correct
    • Handle template variables properly
  2. Content Processing:

    • Check MIME Type to determine how to process content
    • Parse JSON content as objects
    • Handle text content as strings
    • Decode base64 for binary content
  3. Error Handling:

    • Check if content is not null
    • Handle missing resources gracefully
    • Validate content structure before use
  4. Performance:

    • Cache frequently accessed resources
    • Set appropriate timeouts
    • Avoid reading large resources repeatedly
  5. MIME Type Handling:

    • Use MIME Type to determine processing method
    • application/json → Parse as object
    • text/* → Use as string
    • image/* → Process as base64 or binary

Common Errors and Solutions

Error: "Client Id cannot be empty"

Solution:

  • Ensure Connect node executed successfully
  • Pass Client Id from Connect node
  • Verify client connection is active

Error: "Resource URI cannot be empty"

Solution:

  • Provide a valid Resource URI
  • Use List Resources to find available URIs
  • Check URI is properly formatted

Error: "MCP client not found"

Solution:

  • Ensure Connect node executed before Read Resource
  • Verify Client ID is correct
  • Check connection didn't fail or close

Error: "Failed to read resource"

Solution:

  • Verify resource exists on the server
  • Check URI is correct and properly formatted
  • Ensure you have permission to access the resource
  • Check server logs for errors

Null Content

Cause: Resource exists but has no content, or resource not found.

Solution:

  • Check if resource is properly initialized on server
  • Verify URI is correct
  • Check server logs for issues

Tips for Effective Use

  1. List First - Use List Resources to discover available resources
  2. Validate URI - Ensure URI exists before reading
  3. Handle Content - Process content based on MIME Type
  4. Cache Results - Cache static resources to reduce server calls
  5. Parse JSON - JSON content is auto-parsed to objects
  6. Check MIME Type - Use MIME Type to determine processing
  7. Error Handling - Always handle resource not found scenarios

Integration Patterns

Pattern 1: Simple Resource Read

Connect → Read Resource → Use Content

Pattern 2: Discovery and Read

Connect → List Resources → Select → Read Resource → Process

Pattern 3: Multiple Resources

Connect → Read Resource A
→ Read Resource B → Combine
→ Read Resource C

Pattern 4: Conditional Reading

List Resources → Check exists → Read Resource
↓ (if not exists)
Default Value

Pattern 5: Resource Processing Pipeline

Read Resource → Parse → Transform → Validate → Use

Processing Examples

Parse JSON Content

// Content is automatically parsed if it's JSON
if (typeof msg.content === 'object') {
// Already an object
msg.user_name = msg.content.name;
} else {
// Parse if it's a string
const data = JSON.parse(msg.content);
msg.user_name = data.name;
}

Process CSV Content

function parseCSV(csv) {
const lines = csv.trim().split('\n');
const headers = lines[0].split(',');
return lines.slice(1).map(line => {
const values = line.split(',');
return headers.reduce((obj, header, i) => {
obj[header.trim()] = values[i]?.trim();
return obj;
}, {});
});
}

msg.data = parseCSV(msg.content);

Handle Different MIME Types

const mimeType = msg.mime_type;
let processed;

if (mimeType === 'application/json') {
processed = typeof msg.content === 'object'
? msg.content
: JSON.parse(msg.content);
} else if (mimeType === 'text/csv') {
processed = parseCSV(msg.content);
} else if (mimeType?.startsWith('text/')) {
processed = msg.content.toString();
} else {
// Binary or unknown
processed = msg.content;
}

msg.processed_content = processed;

Merge Multiple Resources

// After reading multiple resources
const merged = {
config: msg.config_content,
users: msg.users_content,
products: msg.products_content
};

msg.merged_data = merged;

Validate Resource Content

// Validate JSON structure
if (typeof msg.content !== 'object') {
throw new Error('Expected JSON object');
}

const required = ['id', 'name', 'email'];
const missing = required.filter(field => !msg.content[field]);

if (missing.length > 0) {
throw new Error(`Missing required fields: ${missing.join(', ')}`);
}