Skip to content

fix: encode dynamic URL path segments in SDK and CLI requests#5905

Open
Rsmiyani wants to merge 1 commit into
mem0ai:mainfrom
Rsmiyani:fix/encode-dynamic-url-paths
Open

fix: encode dynamic URL path segments in SDK and CLI requests#5905
Rsmiyani wants to merge 1 commit into
mem0ai:mainfrom
Rsmiyani:fix/encode-dynamic-url-paths

Conversation

@Rsmiyani

Copy link
Copy Markdown

Linked Issue

Closes #5893
Closes #5818

Description

This PR fixes an issue where hosted SDK and CLI methods build API URLs by interpolating caller-provided identifiers directly into URL path segments. When these identifiers contain URL-structural characters (such as /, ?, or #), they alter the generated request URL semantics instead of being treated as a literal path segment.

We resolve this by percent-encoding the dynamic path segment values before inserting them into API paths (e.g. converting org/team?active#frag -> org%2Fteam%3Factive%23frag).

Affected areas fixed:

  1. Python SDK memory paths: Encoded memory_id and entity names in main.py using urllib.parse.quote(..., safe='').
  2. Python CLI memory, entity, and event paths: Encoded path parameters in platform.py using urllib.parse.quote(..., safe='').
  3. TypeScript SDK memory and entity paths: Wrapped template segments in mem0.ts with encodeURIComponent().
  4. Node CLI memory, entity, and event paths: Wrapped template segments in platform.ts with encodeURIComponent().

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactor (no functional changes)
  • Documentation update

Breaking Changes

N/A

Test Coverage

  • I added/updated unit tests
  • I added/updated integration tests
  • I tested manually (describe below)
  • No tests needed (explain why)

Added comprehensive unit tests to verify that structural characters in path parameters are properly percent-encoded:

  • Python SDK: Added TestUrlEncoding and TestAsyncUrlEncoding in tests/test_client.py.
  • Python CLI: Added tests in cli/python/tests/test_backend.py.
  • TypeScript SDK: Added tests in mem0-ts/src/client/tests/memoryClient.urlEncoding.test.ts.
  • Node CLI: Added tests in cli/node/tests/backend.test.ts.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation if needed

@CLAassistant

CLAassistant commented Jun 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Encode dynamic URL path segments in SDK and CLI requests

2 participants