Skip to content

Commit 3fa346b

Browse files
feat(api): expose /system/v1/whoami route
1 parent 570a506 commit 3fa346b

File tree

9 files changed

+148
-2
lines changed

9 files changed

+148
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 106
1+
configured_endpoints: 107
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/mux%2Fmux-323c1dc63b7a75cbabd3a79dcf80ca0afc9c0ae234f4323a39240a4a841583b9.yml
33
openapi_spec_hash: e8fda4e033c6d0e7bc9ee4c629c232fa
4-
config_hash: 245adfa70ec6f84ba48ccaccc26a546c
4+
config_hash: 16b19b97f99dd7265b4619c5a999c751

api.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,17 @@ Methods:
356356
- <code title="get /system/v1/signing-keys">client.system.signingKeys.<a href="./src/resources/system/signing-keys.ts">list</a>({ ...params }) -> SigningKeysBasePage</code>
357357
- <code title="delete /system/v1/signing-keys/{SIGNING_KEY_ID}">client.system.signingKeys.<a href="./src/resources/system/signing-keys.ts">delete</a>(signingKeyId) -> void</code>
358358

359+
## Utilities
360+
361+
Types:
362+
363+
- <code><a href="./src/resources/system/utilities.ts">WhoamiResponse</a></code>
364+
- <code><a href="./src/resources/system/utilities.ts">UtilityWhoamiResponse</a></code>
365+
366+
Methods:
367+
368+
- <code title="get /system/v1/whoami">client.system.utilities.<a href="./src/resources/system/utilities.ts">whoami</a>() -> UtilityWhoamiResponse</code>
369+
359370
# Webhooks
360371

361372
Types:

packages/mcp-server/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,7 @@ The following tools are available in this MCP server.
346346
**The private key is not returned in this response.**
347347
- `list_system_signing_keys` (`read`): Returns a list of signing keys.
348348
- `delete_system_signing_keys` (`write`): Deletes an existing signing key. Use with caution, as this will invalidate any existing signatures and no JWTs can be signed using the key again.
349+
350+
### Resource `system.utilities`:
351+
352+
- `whoami_system_utilities` (`read`): Retrieve information about your current access token, including organization, environment, and permissions. Note that this can only be access with an access token, and _all_ access tokens can access this route, regardless of what permissions they have assigned.

packages/mcp-server/src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ import create_system_signing_keys from './system/signing-keys/create-system-sign
100100
import retrieve_system_signing_keys from './system/signing-keys/retrieve-system-signing-keys';
101101
import list_system_signing_keys from './system/signing-keys/list-system-signing-keys';
102102
import delete_system_signing_keys from './system/signing-keys/delete-system-signing-keys';
103+
import whoami_system_utilities from './system/utilities/whoami-system-utilities';
103104

104105
export const endpoints: Endpoint[] = [];
105106

@@ -203,6 +204,7 @@ addEndpoint(create_system_signing_keys);
203204
addEndpoint(retrieve_system_signing_keys);
204205
addEndpoint(list_system_signing_keys);
205206
addEndpoint(delete_system_signing_keys);
207+
addEndpoint(whoami_system_utilities);
206208

207209
export type Filter = {
208210
type: 'resource' | 'operation' | 'tag' | 'tool';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { maybeFilter } from '@mux/mcp/filtering';
4+
import { Metadata, asTextContentResult } from '@mux/mcp/tools/types';
5+
6+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
7+
import Mux from '@mux/mux-node';
8+
9+
export const metadata: Metadata = {
10+
resource: 'system.utilities',
11+
operation: 'read',
12+
tags: [],
13+
httpMethod: 'get',
14+
httpPath: '/system/v1/whoami',
15+
operationId: 'get-whoami',
16+
};
17+
18+
export const tool: Tool = {
19+
name: 'whoami_system_utilities',
20+
description:
21+
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nRetrieve information about your current access token, including organization, environment, and permissions. Note that this can only be access with an access token, and _all_ access tokens can access this route, regardless of what permissions they have assigned.\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/whoami_response',\n $defs: {\n whoami_response: {\n type: 'object',\n properties: {\n data: {\n type: 'object',\n properties: {\n access_token_name: {\n type: 'string'\n },\n environment_id: {\n type: 'string'\n },\n environment_name: {\n type: 'string'\n },\n environment_type: {\n type: 'string'\n },\n organization_id: {\n type: 'string'\n },\n organization_name: {\n type: 'string'\n },\n permissions: {\n type: 'array',\n items: {\n type: 'string'\n }\n }\n },\n required: [ 'access_token_name',\n 'environment_id',\n 'environment_name',\n 'environment_type',\n 'organization_id',\n 'organization_name',\n 'permissions'\n ]\n }\n },\n required: [ 'data'\n ]\n }\n }\n}\n```",
22+
inputSchema: {
23+
type: 'object',
24+
properties: {
25+
jq_filter: {
26+
type: 'string',
27+
title: 'jq Filter',
28+
description:
29+
'A jq filter to apply to the response to include certain fields. Consult the output schema in the tool description to see the fields that are available.\n\nFor example: to include only the `name` field in every object of a results array, you can provide ".results[].name".\n\nFor more information, see the [jq documentation](https://jqlang.org/manual/).',
30+
},
31+
},
32+
required: [],
33+
},
34+
annotations: {
35+
readOnlyHint: true,
36+
},
37+
};
38+
39+
export const handler = async (client: Mux, args: Record<string, unknown> | undefined) => {
40+
return asTextContentResult(await maybeFilter(args, await client.system.utilities.whoami()));
41+
};
42+
43+
export default { metadata, tool, handler };

src/resources/system/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export {
88
type SigningKeyListParams,
99
} from './signing-keys';
1010
export { System } from './system';
11+
export { Utilities, type WhoamiResponse, type UtilityWhoamiResponse } from './utilities';

src/resources/system/system.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ import {
99
SigningKeys,
1010
SigningKeysBasePage,
1111
} from './signing-keys';
12+
import * as UtilitiesAPI from './utilities';
13+
import { Utilities, UtilityWhoamiResponse, WhoamiResponse } from './utilities';
1214

1315
export class System extends APIResource {
1416
signingKeys: SigningKeysAPI.SigningKeys = new SigningKeysAPI.SigningKeys(this._client);
17+
utilities: UtilitiesAPI.Utilities = new UtilitiesAPI.Utilities(this._client);
1518
}
1619

1720
System.SigningKeys = SigningKeys;
1821
System.SigningKeysBasePage = SigningKeysBasePage;
22+
System.Utilities = Utilities;
1923

2024
export declare namespace System {
2125
export {
@@ -25,4 +29,10 @@ export declare namespace System {
2529
SigningKeysBasePage as SigningKeysBasePage,
2630
type SigningKeyListParams as SigningKeyListParams,
2731
};
32+
33+
export {
34+
Utilities as Utilities,
35+
type WhoamiResponse as WhoamiResponse,
36+
type UtilityWhoamiResponse as UtilityWhoamiResponse,
37+
};
2838
}

src/resources/system/utilities.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../../resource';
4+
import * as Core from '../../core';
5+
6+
export class Utilities extends APIResource {
7+
/**
8+
* Retrieve information about your current access token, including organization,
9+
* environment, and permissions. Note that this can only be access with an access
10+
* token, and _all_ access tokens can access this route, regardless of what
11+
* permissions they have assigned.
12+
*/
13+
whoami(options?: Core.RequestOptions): Core.APIPromise<UtilityWhoamiResponse> {
14+
return (
15+
this._client.get('/system/v1/whoami', {
16+
defaultBaseURL: 'https://api.mux.com',
17+
...options,
18+
}) as Core.APIPromise<{ data: UtilityWhoamiResponse }>
19+
)._thenUnwrap((obj) => obj.data);
20+
}
21+
}
22+
23+
export interface WhoamiResponse {
24+
data: UtilityWhoamiResponse;
25+
}
26+
27+
export interface UtilityWhoamiResponse {
28+
access_token_name: string;
29+
30+
environment_id: string;
31+
32+
environment_name: string;
33+
34+
environment_type: string;
35+
36+
organization_id: string;
37+
38+
organization_name: string;
39+
40+
permissions: Array<string>;
41+
}
42+
43+
export declare namespace Utilities {
44+
export { type WhoamiResponse as WhoamiResponse, type UtilityWhoamiResponse as UtilityWhoamiResponse };
45+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Mux from '@mux/mux-node';
4+
import { Response } from 'node-fetch';
5+
6+
const client = new Mux({
7+
tokenId: 'my token id',
8+
tokenSecret: 'my secret',
9+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
10+
});
11+
12+
describe('resource utilities', () => {
13+
test('whoami', async () => {
14+
const responsePromise = client.system.utilities.whoami();
15+
const rawResponse = await responsePromise.asResponse();
16+
expect(rawResponse).toBeInstanceOf(Response);
17+
const response = await responsePromise;
18+
expect(response).not.toBeInstanceOf(Response);
19+
const dataAndResponse = await responsePromise.withResponse();
20+
expect(dataAndResponse.data).toBe(response);
21+
expect(dataAndResponse.response).toBe(rawResponse);
22+
});
23+
24+
test('whoami: request options instead of params are passed correctly', async () => {
25+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
26+
await expect(client.system.utilities.whoami({ path: '/_stainless_unknown_path' })).rejects.toThrow(
27+
Mux.NotFoundError,
28+
);
29+
});
30+
});

0 commit comments

Comments
 (0)