@creature-ai/sdk 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -207,13 +207,13 @@ interface ToolContext {
207
207
  */
208
208
  instanceId: string;
209
209
  /**
210
- * Creature App Token for identity verification.
210
+ * Creature App Token for identity retrieval.
211
211
  * ONLY present when:
212
212
  * 1. App opted into Creature-managed auth (`auth: { creatureManaged: true }`)
213
213
  * 2. Tool call originated from Creature host
214
214
  *
215
- * Use `verifyCreatureToken(context.creatureToken)` to verify and extract
216
- * user identity for multi-tenant data access.
215
+ * Use `getIdentity(context.creatureToken)` to retrieve user identity
216
+ * for multi-tenant data access.
217
217
  *
218
218
  * @example
219
219
  * ```typescript
@@ -221,7 +221,7 @@ interface ToolContext {
221
221
  * if (!context.creatureToken) {
222
222
  * return { error: "Authentication required" };
223
223
  * }
224
- * const identity = await verifyCreatureToken(context.creatureToken);
224
+ * const identity = await getIdentity(context.creatureToken);
225
225
  * await db.notes.insert({
226
226
  * user_id: identity.user.id,
227
227
  * content,
@@ -557,6 +557,7 @@ declare class App {
557
557
  /**
558
558
  * Format tool result for serverless response.
559
559
  * Shared between Vercel and Lambda adapters.
560
+ * Must include all fields that formatToolResult includes (title, inlineHeight, etc.).
560
561
  */
561
562
  private formatServerlessResult;
562
563
  /**
@@ -714,7 +715,7 @@ declare function htmlLoader(htmlOrPath: string, basePath?: string): () => string
714
715
  declare function wrapServer<T extends McpServer>(server: T): T;
715
716
 
716
717
  /**
717
- * User identity from a verified Creature token.
718
+ * User identity from a Creature token.
718
719
  */
719
720
  interface CreatureUser {
720
721
  /** Unique, stable user identifier */
@@ -725,7 +726,7 @@ interface CreatureUser {
725
726
  name?: string;
726
727
  }
727
728
  /**
728
- * Organization context from a verified Creature token.
729
+ * Organization context from a Creature token.
729
730
  */
730
731
  interface CreatureOrganization {
731
732
  /** Unique organization identifier */
@@ -736,7 +737,7 @@ interface CreatureOrganization {
736
737
  slug: string;
737
738
  }
738
739
  /**
739
- * Project context from a verified Creature token.
740
+ * Project context from a Creature token.
740
741
  */
741
742
  interface CreatureProject {
742
743
  /** Unique project identifier */
@@ -745,15 +746,15 @@ interface CreatureProject {
745
746
  name: string;
746
747
  }
747
748
  /**
748
- * Session context from a verified Creature token.
749
+ * Session context from a Creature token.
749
750
  */
750
751
  interface CreatureSession {
751
752
  /** Unique session identifier */
752
753
  id: string;
753
754
  }
754
755
  /**
755
- * Verified identity claims from a Creature App Token.
756
- * Returned by verifyCreatureToken() on successful verification.
756
+ * Identity claims from a Creature App Token.
757
+ * Returned by getIdentity() on successful retrieval.
757
758
  */
758
759
  interface CreatureIdentity {
759
760
  /** User identity (always present for valid tokens) */
@@ -768,10 +769,10 @@ interface CreatureIdentity {
768
769
  expiresAt: string;
769
770
  }
770
771
  /**
771
- * Error thrown when token verification fails.
772
+ * Error thrown when identity retrieval fails.
772
773
  */
773
- declare class CreatureTokenError extends Error {
774
- /** Error code from the verification API */
774
+ declare class CreatureIdentityError extends Error {
775
+ /** Error code from the identity API */
775
776
  code: string;
776
777
  constructor({ code, message }: {
777
778
  code: string;
@@ -779,9 +780,9 @@ declare class CreatureTokenError extends Error {
779
780
  });
780
781
  }
781
782
  /**
782
- * Configuration for the Creature token verification API.
783
+ * Configuration for the Creature identity API.
783
784
  */
784
- interface VerifyConfig {
785
+ interface IdentityConfig {
785
786
  /**
786
787
  * Base URL for the Creature API.
787
788
  * Defaults to https://api.creature.run
@@ -790,43 +791,46 @@ interface VerifyConfig {
790
791
  apiUrl?: string;
791
792
  }
792
793
  /**
793
- * Verifies a Creature App Token and returns the identity claims.
794
+ * Retrieves user identity from a Creature App Token.
794
795
  *
795
- * Use this in your backend API to authenticate requests from your MCP App UI.
796
- * The token is provided to your UI via `hostContext.creature.token` when you
796
+ * Use this in your MCP App tool handlers to get the authenticated user's
797
+ * identity. The token is provided via `context.creatureToken` when you
797
798
  * opt into Creature-managed auth.
798
799
  *
799
- * @param tokenOrHeader - The App Token (raw) or Authorization header ("Bearer <token>")
800
+ * @param creatureToken - The App Token from context.creatureToken
800
801
  * @param config - Optional configuration (e.g., custom API URL)
801
- * @returns The verified identity claims
802
- * @throws {CreatureTokenError} If verification fails (invalid, expired, or malformed token)
802
+ * @returns The identity claims (user, organization, project, session)
803
+ * @throws {CreatureIdentityError} If the token is invalid, expired, or malformed
803
804
  *
804
805
  * @example
805
806
  * ```typescript
806
- * import { verifyCreatureToken } from "@creature-ai/sdk/server";
807
+ * import { getIdentity } from "@creature-ai/sdk/server";
808
+ *
809
+ * app.tool("save_note", { ... }, async ({ content }, context) => {
810
+ * if (!context.creatureToken) {
811
+ * return { text: "Authentication required", isError: true };
812
+ * }
807
813
  *
808
- * // In your Express/Hono/etc. API handler:
809
- * app.post("/api/notes", async (req, res) => {
810
814
  * try {
811
- * const identity = await verifyCreatureToken(req.headers.authorization);
815
+ * const identity = await getIdentity(context.creatureToken);
812
816
  *
813
817
  * // Use identity to scope data access
814
- * const notes = await db.notes.find({
818
+ * await db.notes.insert({
815
819
  * user_id: identity.user.id,
816
820
  * org_id: identity.organization?.id,
821
+ * content,
817
822
  * });
818
823
  *
819
- * res.json({ notes });
824
+ * return { text: "Note saved" };
820
825
  * } catch (err) {
821
- * if (err instanceof CreatureTokenError) {
822
- * res.status(401).json({ error: err.code, message: err.message });
823
- * } else {
824
- * res.status(500).json({ error: "internal_error" });
826
+ * if (err instanceof CreatureIdentityError) {
827
+ * return { text: err.message, isError: true };
825
828
  * }
829
+ * throw err;
826
830
  * }
827
831
  * });
828
832
  * ```
829
833
  */
830
- declare const verifyCreatureToken: (tokenOrHeader: string | undefined | null, config?: VerifyConfig) => Promise<CreatureIdentity>;
834
+ declare const getIdentity: (creatureToken: string | undefined | null, config?: IdentityConfig) => Promise<CreatureIdentity>;
831
835
 
832
- export { type AdapterOptions, App, type AppConfig, type AwsLambdaOptions, type CreatureIdentity, type CreatureOrganization, type CreatureProject, type CreatureSession, CreatureTokenError, type CreatureUser, type DisplayMode, type IconConfig, type InstanceDestroyContext, MIME_TYPES, type RealtimeAdapter, type ResourceConfig, type StateAdapter, type ToolConfig, type ToolContext, type ToolHandler, type ToolResult, type ToolVisibility, type TransportSessionInfo, type TransportType, type VercelMcpOptions, type WebSocketConnection, createApp, htmlLoader, isHtmlContent, loadHtml, svgToDataUri, verifyCreatureToken, wrapServer };
836
+ export { type AdapterOptions, App, type AppConfig, type AwsLambdaOptions, type CreatureIdentity, CreatureIdentityError, type CreatureOrganization, type CreatureProject, type CreatureSession, type CreatureUser, type DisplayMode, type IconConfig, type InstanceDestroyContext, MIME_TYPES, type RealtimeAdapter, type ResourceConfig, type StateAdapter, type ToolConfig, type ToolContext, type ToolHandler, type ToolResult, type ToolVisibility, type TransportSessionInfo, type TransportType, type VercelMcpOptions, type WebSocketConnection, createApp, getIdentity, htmlLoader, isHtmlContent, loadHtml, svgToDataUri, wrapServer };
@@ -14121,6 +14121,7 @@ var App = class {
14121
14121
  /**
14122
14122
  * Format tool result for serverless response.
14123
14123
  * Shared between Vercel and Lambda adapters.
14124
+ * Must include all fields that formatToolResult includes (title, inlineHeight, etc.).
14124
14125
  */
14125
14126
  formatServerlessResult(result, instanceId, websocketUrl) {
14126
14127
  const text = result.text || JSON.stringify(result.data || {});
@@ -14135,6 +14136,8 @@ var App = class {
14135
14136
  content: [{ type: "text", text }],
14136
14137
  structuredContent: {
14137
14138
  ...result.data,
14139
+ ...result.title && { title: result.title },
14140
+ ...result.inlineHeight && { inlineHeight: result.inlineHeight },
14138
14141
  instanceId,
14139
14142
  ...websocketUrl && { websocketUrl }
14140
14143
  },
@@ -14889,12 +14892,12 @@ function wrapServer(server) {
14889
14892
  }
14890
14893
 
14891
14894
  // src/server/auth.ts
14892
- var CreatureTokenError = class extends Error {
14893
- /** Error code from the verification API */
14895
+ var CreatureIdentityError = class extends Error {
14896
+ /** Error code from the identity API */
14894
14897
  code;
14895
14898
  constructor({ code, message }) {
14896
14899
  super(message);
14897
- this.name = "CreatureTokenError";
14900
+ this.name = "CreatureIdentityError";
14898
14901
  this.code = code;
14899
14902
  }
14900
14903
  };
@@ -14906,33 +14909,32 @@ var extractToken = (tokenOrHeader) => {
14906
14909
  }
14907
14910
  return trimmed;
14908
14911
  };
14909
- var verifyCreatureToken = async (tokenOrHeader, config) => {
14910
- if (!tokenOrHeader) {
14911
- throw new CreatureTokenError({
14912
+ var getIdentity = async (creatureToken, config) => {
14913
+ if (!creatureToken) {
14914
+ throw new CreatureIdentityError({
14912
14915
  code: "missing_token",
14913
- message: "No token provided. Expected Authorization header or raw token."
14916
+ message: "No token provided. Pass context.creatureToken to getIdentity()."
14914
14917
  });
14915
14918
  }
14916
- const token = extractToken(tokenOrHeader);
14919
+ const token = extractToken(creatureToken);
14917
14920
  if (!token) {
14918
- throw new CreatureTokenError({
14921
+ throw new CreatureIdentityError({
14919
14922
  code: "missing_token",
14920
- message: "Empty token after extraction from Authorization header."
14923
+ message: "Empty token after extraction."
14921
14924
  });
14922
14925
  }
14923
14926
  const apiUrl = config?.apiUrl || DEFAULT_API_URL;
14924
- const verifyUrl = `${apiUrl}/apps/v1/token/verify`;
14927
+ const identityUrl = `${apiUrl}/apps/v1/identity`;
14925
14928
  let response;
14926
14929
  try {
14927
- response = await fetch(verifyUrl, {
14928
- method: "POST",
14930
+ response = await fetch(identityUrl, {
14931
+ method: "GET",
14929
14932
  headers: {
14930
- Authorization: `Bearer ${token}`,
14931
- "Content-Type": "application/json"
14933
+ Authorization: `Bearer ${token}`
14932
14934
  }
14933
14935
  });
14934
14936
  } catch (err) {
14935
- throw new CreatureTokenError({
14937
+ throw new CreatureIdentityError({
14936
14938
  code: "network_error",
14937
14939
  message: `Failed to reach Creature API: ${err instanceof Error ? err.message : "Unknown error"}`
14938
14940
  });
@@ -14943,44 +14945,44 @@ var verifyCreatureToken = async (tokenOrHeader, config) => {
14943
14945
  errorData = await response.json();
14944
14946
  } catch {
14945
14947
  }
14946
- throw new CreatureTokenError({
14947
- code: errorData.error || "verification_failed",
14948
- message: errorData.error_description || `Token verification failed (HTTP ${response.status})`
14948
+ throw new CreatureIdentityError({
14949
+ code: errorData.error || "identity_error",
14950
+ message: errorData.error_description || `Identity request failed (HTTP ${response.status})`
14949
14951
  });
14950
14952
  }
14951
14953
  let data;
14952
14954
  try {
14953
14955
  data = await response.json();
14954
14956
  } catch {
14955
- throw new CreatureTokenError({
14957
+ throw new CreatureIdentityError({
14956
14958
  code: "invalid_response",
14957
14959
  message: "Invalid JSON response from Creature API"
14958
14960
  });
14959
14961
  }
14960
- if (!data.valid || !data.claims?.user) {
14961
- throw new CreatureTokenError({
14962
+ if (!data.user) {
14963
+ throw new CreatureIdentityError({
14962
14964
  code: "invalid_token",
14963
14965
  message: "Token is not valid"
14964
14966
  });
14965
14967
  }
14966
14968
  return {
14967
- user: data.claims.user,
14968
- organization: data.claims.organization,
14969
- project: data.claims.project,
14970
- session: data.claims.session,
14969
+ user: data.user,
14970
+ organization: data.organization,
14971
+ project: data.project,
14972
+ session: data.session,
14971
14973
  expiresAt: data.expires_at
14972
14974
  };
14973
14975
  };
14974
14976
  export {
14975
14977
  App,
14976
- CreatureTokenError,
14978
+ CreatureIdentityError,
14977
14979
  MIME_TYPES,
14978
14980
  createApp,
14981
+ getIdentity,
14979
14982
  htmlLoader,
14980
14983
  isHtmlContent,
14981
14984
  loadHtml,
14982
14985
  svgToDataUri,
14983
- verifyCreatureToken,
14984
14986
  wrapServer
14985
14987
  };
14986
14988
  //# sourceMappingURL=index.js.map