Skip to content

Conversation

@CoveMB
Copy link
Contributor

@CoveMB CoveMB commented Nov 10, 2025

Fixes #707

Summary

Expose a configurable tokenUri for Stellar non-fungible contracts across the generator,
tooling, and UI so deployments can mint NFTs with accurate metadata.

Description

  • Core defaults now include tokenUri, it flows through buildNonFungible and addBase
    so metadata is set from the provided value (packages/core/stellar/src/non-fungible.ts:19,
    packages/core/stellar/src/non-fungible.ts:67, packages/core/stellar/src/non-fungible.ts:125).
  • Generator blueprints, AI descriptions, schemas, MCP tooling, and the AI assistant function
    definition all surface the new field (packages/core/stellar/src/generate/non-fungible.ts:11,
    packages/common/src/ai/descriptions/stellar.ts:25,
    packages/mcp/src/stellar/schemas.ts:60,
    packages/mcp/src/stellar/tools/non-fungible.ts:16,
    packages/ui/api/ai-assistant/function-definitions/stellar.ts:102).
  • The Svelte controls now offer a token URI input so users can configure it visually
    (packages/ui/src/stellar/NonFungibleControls.svelte:56).
  • Tests, snapshots, and MCP tool coverage exercise the custom URI path
    (packages/core/stellar/src/non-fungible.test.ts:156,
    packages/mcp/src/stellar/tools/non-fungible.test.ts:37).

Motivation / Context

Developers need Soroban NFT contracts to advertise the correct metadata host. Allowing tokenUri
to pass through every surface removes the hard-coded placeholder and keeps wizard output accurate.

Changes

  • Added the optional tokenUri parameter throughout the Stellar NFT builder, tooling, AI, and UI.

Affected functions

  • packages/core/stellar/src/non-fungible.ts:67buildNonFungible now forwards tokenUri
    into the contract builder.
  • packages/core/stellar/src/non-fungible.ts:125addBase writes metadata from the
    user-specified URI instead of a literal string.
  • packages/mcp/src/stellar/tools/non-fungible.ts:8registerStellarNonFungible
    accepts the new argument so MCP requests round-trip it.
  • packages/mcp/src/stellar/schemas.ts:60nonFungibleSchema validates tokenUri,
    enabling AI/MCP prompts to describe it.
  • packages/ui/src/stellar/NonFungibleControls.svelte:56 – UI exposes a bound input so
    wizard users can supply the URI.

Security Impact

✅ No security-impacting changes; only metadata strings are forwarded to contract initialization.
✅ No additional security-sensitive code paths were introduced.

Testing

  • pnpm test --filter "packages/core/stellar -- non-fungible" (covers the new
    non-fungible custom token uri snapshot) – not run in this environment.
  • pnpm test --filter "packages/mcp -- non-fungible" – not run in this environment.
  • Manual: use the Stellar NFT wizard UI to enter a custom Token URI, generate the
    contract, and confirm the emitted Soroban code sets that URI in Base::set_metadata.

Backward Compatibility

  • ✅ No breaking changes; tokenUri is optional with a default identical to prior behavior.
  • ✅ No migrations required; existing saved configs continue to use the default URI unless set.

@CoveMB CoveMB requested review from a team as code owners November 10, 2025 16:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The PR adds a tokenUri optional field to Stellar NFT contract generation, enabling users to customize token URI metadata. The field propagates through descriptions, core generation logic, schemas, MCP tools, AI function definitions, and UI controls.

Changes

Cohort / File(s) Summary
Core NFT Logic
packages/core/stellar/src/non-fungible.ts, packages/core/stellar/src/generate/non-fungible.ts
Added optional tokenUri field to NonFungibleOptions interface with default value 'www.mytoken.com'. Updated addBase function signature to accept tokenUri parameter and pass it through the generation pipeline. Added tokenUri to the blueprint for generating alternatives.
Description & Schema
packages/common/src/ai/descriptions/stellar.ts, packages/mcp/src/stellar/schemas.ts
Added tokenUri property to stellarNonFungibleDescriptions object and corresponding optional field to nonFungibleSchema with descriptive metadata.
MCP Tool Integration
packages/mcp/src/stellar/tools/non-fungible.ts, packages/mcp/src/stellar/tools/non-fungible.test.ts
Updated tool-registration callback to destructure and pass tokenUri from options. Added test coverage for tokenUri in both basic and extended scenarios.
UI Layer
packages/ui/api/ai-assistant/function-definitions/stellar.ts, packages/ui/src/stellar/NonFungibleControls.svelte
Added tokenUri to AI function definition parameters with string type and description. Introduced new "Token URI" input field in Settings with HelpTooltip, bound to opts.tokenUri, and error binding.
Test Coverage
packages/core/stellar/src/non-fungible.test.ts, packages/core/stellar/src/non-fungible.test.ts.md
Added test case "non-fungible custom token uri" exercising the new field with example URI. Added corresponding snapshot example showing contract setup with custom metadata URI.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Pattern consistency: The field addition follows a uniform, additive pattern across all layers without structural refactoring or complex logic changes.
  • No API signature breaking: The tokenUri field is optional in public interfaces, maintaining backward compatibility.
  • Areas requiring attention:
    • Verify tokenUri properly threads through from UI input → MCP tool → core generation → contract metadata.
    • Confirm default value ('www.mytoken.com') and placeholder text ('https://...') are appropriate and aligned.
    • Ensure error handling for tokenUri is consistent with other optional fields in the UI component.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title '[Stellar] add token URI setting' clearly and concisely describes the main change: adding a configurable token URI feature for Stellar non-fungible contracts.
Description check ✅ Passed The PR description comprehensively explains the changes, motivation, affected functions, and testing approach, all directly related to adding the tokenUri feature across multiple packages.
Linked Issues check ✅ Passed The PR fully addresses issue #707 by adding a configurable Token URI field throughout the Stellar NFT builder, tooling, AI, and UI so users can provide metadata host for NFTs.
Out of Scope Changes check ✅ Passed All changes are directly related to adding tokenUri support to Stellar non-fungible contracts; no unrelated modifications are present in the changeset.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/stellar/src/non-fungible.ts (1)

16-29: Consider adding protocol to default tokenUri.

The default tokenUri value 'www.mytoken.com' lacks a protocol (http:// or https://), while test examples use 'https://example.com/nft/'. For consistency and to avoid potential issues with URI consumers, consider using a fully-qualified URL as the default.

-  tokenUri: 'www.mytoken.com',
+  tokenUri: 'https://www.mytoken.com',
🧹 Nitpick comments (2)
packages/mcp/src/stellar/schemas.ts (1)

60-60: Consider adding URL format validation.

The tokenUri field is correctly added as an optional string with the appropriate description. However, you might consider adding URL format validation using Zod's .url() method to catch malformed URIs early:

-  tokenUri: z.string().optional().describe(stellarNonFungibleDescriptions.tokenUri),
+  tokenUri: z.string().url().optional().describe(stellarNonFungibleDescriptions.tokenUri),

This would provide better input validation and clearer error messages when users provide invalid URIs.

packages/mcp/src/stellar/tools/non-fungible.test.ts (1)

42-65: Consider adding a test case for default tokenUri behavior.

The comprehensive test correctly includes tokenUri. However, consider adding a test case that omits tokenUri to verify that the default value is properly applied, ensuring backward compatibility.

Example test case to add in non-fungible.test.ts:

test('default tokenUri', async t => {
  const params: z.infer<typeof t.context.schema> = {
    name: 'TestToken',
    symbol: 'TST',
    // tokenUri intentionally omitted to test default
  };
  await assertAPIEquivalence(t, params, nonFungible.print);
});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c1fa0f and 3ace710.

⛔ Files ignored due to path filters (1)
  • packages/core/stellar/src/non-fungible.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (10)
  • packages/common/src/ai/descriptions/stellar.ts (1 hunks)
  • packages/core/stellar/src/generate/non-fungible.ts (1 hunks)
  • packages/core/stellar/src/non-fungible.test.ts (1 hunks)
  • packages/core/stellar/src/non-fungible.test.ts.md (1 hunks)
  • packages/core/stellar/src/non-fungible.ts (5 hunks)
  • packages/mcp/src/stellar/schemas.ts (1 hunks)
  • packages/mcp/src/stellar/tools/non-fungible.test.ts (2 hunks)
  • packages/mcp/src/stellar/tools/non-fungible.ts (1 hunks)
  • packages/ui/api/ai-assistant/function-definitions/stellar.ts (1 hunks)
  • packages/ui/src/stellar/NonFungibleControls.svelte (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-18T20:17:09.709Z
Learnt from: ericglau
Repo: OpenZeppelin/contracts-wizard PR: 652
File: packages/mcp/src/confidential/schemas.ts:40-46
Timestamp: 2025-09-18T20:17:09.709Z
Learning: MCP tool schemas for confidential contracts can be more restrictive than the core API. For the votes field in confidential fungible tokens, the MCP schema only accepts 'blocknumber' or 'timestamp' strings because undefined behaves functionally equivalent to false, eliminating the need to explicitly accept boolean values in the tool definition.

Applied to files:

  • packages/mcp/src/stellar/schemas.ts
🧬 Code graph analysis (3)
packages/mcp/src/stellar/schemas.ts (1)
packages/common/src/ai/descriptions/stellar.ts (1)
  • stellarNonFungibleDescriptions (21-26)
packages/mcp/src/stellar/tools/non-fungible.ts (1)
packages/core/stellar/src/non-fungible.ts (1)
  • NonFungibleOptions (35-46)
packages/ui/api/ai-assistant/function-definitions/stellar.ts (1)
packages/common/src/ai/descriptions/stellar.ts (1)
  • stellarNonFungibleDescriptions (21-26)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build (stellar, compile)
  • GitHub Check: build (solidity, default)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (11)
packages/core/stellar/src/non-fungible.test.ts.md (1)

912-943: LGTM!

The new snapshot correctly demonstrates a Non-Fungible token contract with a custom token URI. The generated code structure is consistent with other test snapshots, and the URI format includes the protocol and trailing slash as expected for NFT metadata.

packages/core/stellar/src/non-fungible.test.ts (1)

156-158: LGTM!

The test case correctly validates the custom token URI functionality by passing the tokenUri option and snapshotting the generated contract. The test placement and structure align with existing test patterns in the file.

packages/mcp/src/stellar/tools/non-fungible.ts (1)

13-29: LGTM!

The tokenUri parameter is correctly added to the MCP tool callback, destructured from the input, and passed through to the NonFungibleOptions object. The implementation is consistent with other optional parameters in the tool.

packages/common/src/ai/descriptions/stellar.ts (1)

25-25: LGTM!

The description for tokenUri is clear and accurately explains that it's the metadata URI returned by the token contract for each NFT. The wording is consistent with other descriptions in the file.

packages/ui/src/stellar/NonFungibleControls.svelte (1)

54-60: LGTM!

The Token URI input field is well-implemented with proper data binding, error handling, and user guidance. The help tooltip clearly explains the purpose, and the placeholder suggests the expected URL format.

packages/ui/api/ai-assistant/function-definitions/stellar.ts (1)

102-105: LGTM!

The tokenUri parameter is correctly added to the AI function definition with the appropriate type and description. The field is properly marked as optional, which maintains backward compatibility with existing integrations.

packages/mcp/src/stellar/tools/non-fungible.test.ts (1)

33-40: LGTM! Test coverage for tokenUri added correctly.

The test correctly includes the new tokenUri field in the basic test case, following the same pattern as name and symbol.

packages/core/stellar/src/non-fungible.ts (4)

35-46: LGTM! Interface updated correctly.

The tokenUri field is appropriately added as an optional string parameter, maintaining backward compatibility.


48-61: LGTM! Default handling implemented correctly.

The tokenUri field properly falls back to the default value using the nullish coalescing operator, consistent with other fields.


67-123: LGTM! tokenUri properly propagated through build flow.

The tokenUri is correctly passed to addBase after conversion via toByteArray, following the same pattern as name and symbol fields.


125-159: LGTM! Function signature and usage updated correctly.

The addBase function signature correctly includes the tokenUri parameter, and the generated Rust code properly uses it in the metadata initialization. The implementation follows the established pattern for name and symbol fields.

const blueprint = {
name: ['MyToken'],
symbol: ['MTK'],
tokenUri: ['www.mytoken.com'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Inconsistent URI format in default value.

The default tokenUri value 'www.mytoken.com' lacks the protocol prefix, while the test example uses 'https://example.com/nfts/' and the UI placeholder suggests 'https://...'. This inconsistency may confuse users about the expected URI format.

Consider using a consistent format with the protocol included:

-  tokenUri: ['www.mytoken.com'],
+  tokenUri: ['https://www.mytoken.com'],

This aligns with the test example and UI guidance, making it clearer that full URIs (including protocol) are expected.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
tokenUri: ['www.mytoken.com'],
tokenUri: ['https://www.mytoken.com'],
🤖 Prompt for AI Agents
In packages/core/stellar/src/generate/non-fungible.ts around line 11, the
default tokenUri value is 'www.mytoken.com' which omits the protocol and is
inconsistent with tests and UI placeholders; update the default to a fully
qualified URI including the protocol (e.g., 'https://example.com/nfts/' or
'https://www.mytoken.com') so it matches the expected format across tests and UI
guidance.

Co-authored-by: Eric Lau <ericglau@outlook.com>
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.

Token URI Setting in Stellar NFT Contract Settings

3 participants