mcp-use 2.0.0-beta.31 → 2.0.0-beta.32

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.
package/dist/context.d.ts CHANGED
@@ -1,17 +1,127 @@
1
- import { type InputRequiredResult, type RequestStateAccessor, type ServerContext, type StandardSchemaWithJSON } from "@modelcontextprotocol/server";
1
+ import { type ClientCapabilities, type Implementation, type InputRequiredResult, type RequestStateAccessor, type ServerContext, type StandardSchemaWithJSON } from "@modelcontextprotocol/server";
2
2
  import type { Context, Env, HonoRequest as HonoRequestType } from "hono";
3
3
  /**
4
- * Per-request client capability queries.
4
+ * OpenAI-specific end-user hints declared in request metadata.
5
5
  *
6
- * Reads the modern per-request envelope only — never session state.
6
+ * All fields are optional, client-reported, and unverified. Use
7
+ * {@link OAuthAuth.user} for an authenticated identity.
8
+ */
9
+ export interface UserContext {
10
+ /** Requested BCP 47 locale from `openai/locale` or legacy `webplus/i18n`. */
11
+ locale?: string;
12
+ /** Best-effort browser or host identifier from `openai/userAgent`. */
13
+ userAgent?: string;
14
+ /** Coarse end-user location from `openai/userLocation`. */
15
+ location?: {
16
+ /** City name, when supplied. */
17
+ city?: string;
18
+ /** Region or state name, when supplied. */
19
+ region?: string;
20
+ /** Country identifier, when supplied. */
21
+ country?: string;
22
+ /** IANA timezone identifier, when supplied. */
23
+ timezone?: string;
24
+ /** Approximate latitude; clients may encode coordinates as strings or numbers. */
25
+ latitude?: string | number;
26
+ /** Approximate longitude; clients may encode coordinates as strings or numbers. */
27
+ longitude?: string | number;
28
+ };
29
+ /** Client-reported subject hint from `openai/subject`. */
30
+ subject?: string;
31
+ /** Client-reported conversation hint from `openai/session`. */
32
+ conversationId?: string;
33
+ /** Client-reported organization hint from `openai/organization`. */
34
+ organizationId?: string;
35
+ }
36
+ /**
37
+ * Per-request client metadata and capability queries.
38
+ *
39
+ * Reads only the current request's metadata — never session state.
7
40
  */
8
41
  export interface RequestClientContext {
42
+ /**
43
+ * Checks whether this request declares a top-level client capability.
44
+ *
45
+ * @param capability - Capability name such as `sampling`, `elicitation`,
46
+ * `roots`, or `extensions`.
47
+ * @returns `true` when the current request advertises the capability.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * if (ctx.client.can("elicitation")) {
52
+ * // Shape the result for an elicitation-capable client.
53
+ * }
54
+ * ```
55
+ */
56
+ can(capability: string): boolean;
57
+ /**
58
+ * Returns the capabilities declared by the client for this request.
59
+ *
60
+ * The returned object is a shallow copy. Requests without the modern
61
+ * metadata envelope return an empty object.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const capabilities = ctx.client.capabilities();
66
+ * const supportsFormElicitation = capabilities.elicitation?.form !== undefined;
67
+ * ```
68
+ */
69
+ capabilities(): ClientCapabilities;
70
+ /**
71
+ * Returns one extension settings object declared for this request.
72
+ *
73
+ * @param id - Namespaced extension identifier, such as
74
+ * `io.modelcontextprotocol/ui`.
75
+ * @returns A shallow copy of the extension settings, or `undefined` when the
76
+ * current request does not advertise the extension.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const ui = ctx.client.extension("io.modelcontextprotocol/ui");
81
+ * ```
82
+ */
83
+ extension(id: string): NonNullable<ClientCapabilities["extensions"]>[string] | undefined;
84
+ /**
85
+ * Returns the client implementation metadata declared for this request.
86
+ *
87
+ * Valid modern requests include `name` and `version`. The partial return
88
+ * type preserves v1 ergonomics for legacy requests without an envelope.
89
+ * The returned object is a shallow copy.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const { name, version } = ctx.client.info();
94
+ * ```
95
+ */
96
+ info(): Partial<Implementation>;
97
+ /**
98
+ * Returns normalized OpenAI-specific end-user hints for this request.
99
+ *
100
+ * The data comes from ordinary request `_meta`, not the MCP client-info
101
+ * envelope. It is client-reported and must not be used for authentication
102
+ * or authorization. Each call returns a fresh object, including a fresh
103
+ * location object. Requests without recognized metadata return `undefined`.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const caller = ctx.client.user();
108
+ * const locale = caller?.locale ?? "en";
109
+ * ```
110
+ */
111
+ user(): UserContext | undefined;
9
112
  /**
10
113
  * Whether this request's client advertises MCP Apps / UI support.
11
114
  *
12
115
  * True when the client declares the `io.modelcontextprotocol/ui` extension
13
116
  * with `text/html;profile=mcp-app` in `mimeTypes`. Legacy (non-envelope)
14
117
  * requests always return `false`.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * if (ctx.client.supportsViews()) {
122
+ * // Return a view-optimized result.
123
+ * }
124
+ * ```
15
125
  */
16
126
  supportsViews(): boolean;
17
127
  }
package/dist/index.d.ts CHANGED
@@ -53,7 +53,7 @@ export type { MiddlewareContext, McpMiddlewareContext, McpCompleteEventListenerF
53
53
  export { composeMiddleware, createMcpEventListenerEntry, createMcpMiddlewareEntry, matchesPattern, } from "./middleware/mcp-middleware.js";
54
54
  export type { NodeRequestHandler } from "./node-bridge.js";
55
55
  export type { FromOpenAPIOptions, OpenAPIAuth, OpenAPIDocument, OpenAPIExcludeRule, } from "./openapi/index.js";
56
- export type { Elicit, ElicitationResult, OAuthAuth, RequestClientContext, RequestContext, } from "./context.js";
56
+ export type { Elicit, ElicitationResult, OAuthAuth, RequestClientContext, RequestContext, UserContext, } from "./context.js";
57
57
  export type { InferToolInput, InferToolName, InferToolOutput, ToolCallback, ToolDefinition, ToolRef, ToolResult, ToolViewConfig, } from "./tools.js";
58
58
  export type { ExternalViewManifestEntry, InlineViewManifestEntry, UiPermissions, ViewManifestEntry, ViewsManifest, } from "./views/index.js";
59
59
  export type { InferTemplateParams, ResourceCallback, ResourceDefinition, ResourceTemplateCallback, ResourceTemplateCompleter, ResourceTemplateCompletions, ResourceTemplateDefinition, TemplateVariableValue, } from "./resources.js";
package/dist/index.js CHANGED
@@ -319,6 +319,7 @@ function parsePort(value) {
319
319
  // src/context.ts
320
320
  import {
321
321
  CLIENT_CAPABILITIES_META_KEY as CLIENT_CAPABILITIES_META_KEY2,
322
+ CLIENT_INFO_META_KEY,
322
323
  inputRequired,
323
324
  inputResponse
324
325
  } from "@modelcontextprotocol/server";
@@ -384,11 +385,84 @@ function requireOAuthAuthInfo(authInfo) {
384
385
  throw new Error("OAuth callback did not receive mapped AuthInfo.extra");
385
386
  }
386
387
  }
388
+ function stringValue(value) {
389
+ return typeof value === "string" ? value : void 0;
390
+ }
391
+ function coordinateValue(value) {
392
+ if (typeof value === "string") return value;
393
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
394
+ }
395
+ function normalizeUserContext(meta) {
396
+ if (meta === void 0) return void 0;
397
+ const locale = stringValue(meta["openai/locale"]) ?? stringValue(meta["webplus/i18n"]);
398
+ const userAgent = stringValue(meta["openai/userAgent"]);
399
+ const subject = stringValue(meta["openai/subject"]);
400
+ const conversationId = stringValue(meta["openai/session"]);
401
+ const organizationId = stringValue(meta["openai/organization"]);
402
+ const rawLocation = meta["openai/userLocation"];
403
+ let location;
404
+ if (typeof rawLocation === "object" && rawLocation !== null && !Array.isArray(rawLocation)) {
405
+ const values = rawLocation;
406
+ const normalized = {
407
+ city: stringValue(values.city),
408
+ region: stringValue(values.region),
409
+ country: stringValue(values.country),
410
+ timezone: stringValue(values.timezone),
411
+ latitude: coordinateValue(values.latitude),
412
+ longitude: coordinateValue(values.longitude)
413
+ };
414
+ const entries = Object.entries(normalized).filter(
415
+ (entry) => entry[1] !== void 0
416
+ );
417
+ if (entries.length > 0) {
418
+ location = Object.fromEntries(entries);
419
+ }
420
+ }
421
+ if (locale === void 0 && userAgent === void 0 && location === void 0 && subject === void 0 && conversationId === void 0 && organizationId === void 0) {
422
+ return void 0;
423
+ }
424
+ return {
425
+ ...locale !== void 0 && { locale },
426
+ ...userAgent !== void 0 && { userAgent },
427
+ ...location !== void 0 && { location },
428
+ ...subject !== void 0 && { subject },
429
+ ...conversationId !== void 0 && { conversationId },
430
+ ...organizationId !== void 0 && { organizationId }
431
+ };
432
+ }
387
433
  function toClientContext(ctx) {
388
- const envelopeCaps = ctx.mcpReq.envelope?.[CLIENT_CAPABILITIES_META_KEY2];
434
+ const envelope = ctx.mcpReq.envelope;
435
+ const capabilities = {
436
+ ...envelope?.[CLIENT_CAPABILITIES_META_KEY2] ?? {}
437
+ };
438
+ const info = {
439
+ ...envelope?.[CLIENT_INFO_META_KEY] ?? {}
440
+ };
441
+ const user = normalizeUserContext(ctx.mcpReq._meta);
389
442
  return {
443
+ can(capability) {
444
+ return Object.hasOwn(capabilities, capability);
445
+ },
446
+ capabilities() {
447
+ return { ...capabilities };
448
+ },
449
+ extension(id) {
450
+ const settings = capabilities.extensions?.[id];
451
+ return settings === void 0 ? void 0 : { ...settings };
452
+ },
453
+ info() {
454
+ return { ...info };
455
+ },
456
+ user() {
457
+ return user === void 0 ? void 0 : {
458
+ ...user,
459
+ ...user.location !== void 0 && {
460
+ location: { ...user.location }
461
+ }
462
+ };
463
+ },
390
464
  supportsViews() {
391
- return supportsViews(envelopeCaps);
465
+ return supportsViews(capabilities);
392
466
  }
393
467
  };
394
468
  }
@@ -871,7 +945,7 @@ function normalizeMcpMiddlewarePattern(raw) {
871
945
 
872
946
  // src/logging.ts
873
947
  import {
874
- CLIENT_INFO_META_KEY,
948
+ CLIENT_INFO_META_KEY as CLIENT_INFO_META_KEY2,
875
949
  isJSONRPCRequest
876
950
  } from "@modelcontextprotocol/server";
877
951
  function colorsEnabled() {
@@ -949,7 +1023,7 @@ function inlineJson(value) {
949
1023
  function formatClientIdentity(message) {
950
1024
  const meta = message.params?._meta;
951
1025
  if (meta === void 0) return void 0;
952
- const info = meta[CLIENT_INFO_META_KEY];
1026
+ const info = meta[CLIENT_INFO_META_KEY2];
953
1027
  if (typeof info !== "object" || info === null || typeof info.name !== "string") {
954
1028
  return void 0;
955
1029
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcp-use",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.31",
4
+ "version": "2.0.0-beta.32",
5
5
  "description": "MCP framework and CLI built on the official v2 SDK",
6
6
  "author": "mcp-use, Inc.",
7
7
  "license": "MIT",
@@ -89,7 +89,7 @@
89
89
  "@modelcontextprotocol/server": "2.0.0-beta.5",
90
90
  "hono": "^4.12.27",
91
91
  "jose": "^6.1.3",
92
- "@mcp-use/inspector": "20.0.0-beta.23",
92
+ "@mcp-use/inspector": "20.0.0-beta.24",
93
93
  "@mcp-use/cli": "4.0.0-beta.6"
94
94
  },
95
95
  "peerDependencies": {
@@ -123,8 +123,8 @@
123
123
  "vite": "^8.0.16",
124
124
  "vitest": "^4.1.9",
125
125
  "zod": "^4.4.3",
126
- "mcp-use": "2.0.0-beta.31",
127
- "@mcp-use/client": "2.0.0-beta.12"
126
+ "@mcp-use/client": "2.0.0-beta.12",
127
+ "mcp-use": "2.0.0-beta.32"
128
128
  },
129
129
  "publishConfig": {
130
130
  "access": "public"