Repository navigation
feat: MCP tokens section in user settings #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import type { Ref } from 'vue'; | ||
| import { onMounted, ref } from 'vue'; | ||
| import type { McpToken, McpTokenPermission } from '@/domain/entities/McpToken'; | ||
| import { userSettingsService } from '@/domain'; | ||
|
|
||
| interface UseUserMcpSettingsComposableState { | ||
| /** | ||
| * MCP tokens of the current user, newest first | ||
| */ | ||
| tokens: Ref<McpToken[]>; | ||
|
|
||
| /** | ||
| * Whether tokens are being loaded. Tokens should not be created meanwhile: | ||
| * the loaded list would replace the created token | ||
| */ | ||
| isLoading: Ref<boolean>; | ||
|
|
||
| /** | ||
| * Whether tokens failed to load | ||
| */ | ||
| hasLoadError: Ref<boolean>; | ||
|
|
||
| /** | ||
| * Loads MCP tokens of the current user | ||
| */ | ||
| loadTokens(): Promise<void>; | ||
|
|
||
| /** | ||
| * Creates new MCP token and adds it to the list | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| * @returns plain token, it is not available later | ||
| */ | ||
| createToken(label: string, permission: McpTokenPermission): Promise<string>; | ||
|
|
||
| /** | ||
| * Revokes MCP token and removes it from the list | ||
| * @param id - token id | ||
| */ | ||
| revokeToken(id: McpToken['id']): Promise<void>; | ||
| } | ||
|
|
||
| /** | ||
| * Methods for managing MCP tokens of the current user | ||
| */ | ||
| export default function useUserMcpSettings(): UseUserMcpSettingsComposableState { | ||
| /** | ||
| * MCP tokens of the current user | ||
| */ | ||
| const tokens = ref<McpToken[]>([]); | ||
|
|
||
| /** | ||
| * Whether tokens are being loaded | ||
| */ | ||
| const isLoading = ref(true); | ||
|
|
||
| /** | ||
| * Whether tokens failed to load | ||
| */ | ||
| const hasLoadError = ref(false); | ||
|
|
||
| /** | ||
| * Loads MCP tokens of the current user | ||
| */ | ||
| async function loadTokens(): Promise<void> { | ||
| isLoading.value = true; | ||
| hasLoadError.value = false; | ||
|
|
||
| try { | ||
| tokens.value = await userSettingsService.getMcpTokens(); | ||
| } catch { | ||
| hasLoadError.value = true; | ||
| } finally { | ||
| isLoading.value = false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates new MCP token and adds it to the list | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| */ | ||
| async function createToken(label: string, permission: McpTokenPermission): Promise<string> { | ||
| const { token, item } = await userSettingsService.createMcpToken(label, permission); | ||
|
|
||
| tokens.value = [item, ...tokens.value]; | ||
|
|
||
| return token; | ||
| } | ||
|
|
||
| /** | ||
| * Revokes MCP token and removes it from the list | ||
| * @param id - token id | ||
| */ | ||
| async function revokeToken(id: McpToken['id']): Promise<void> { | ||
| await userSettingsService.revokeMcpToken(id); | ||
|
|
||
| tokens.value = tokens.value.filter(token => token.id !== id); | ||
| } | ||
|
|
||
| onMounted(async () => { | ||
| await loadTokens(); | ||
| }); | ||
|
|
||
| return { | ||
| tokens, | ||
| isLoading, | ||
| hasLoadError, | ||
| loadTokens, | ||
| createToken, | ||
| revokeToken, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * What MCP client can do with notes of the token owner | ||
| */ | ||
| export type McpTokenPermission = 'read' | 'write'; | ||
|
|
||
| /** | ||
| * Personal token used by MCP clients (Claude, Cursor, etc.) to access user notes | ||
| */ | ||
| export interface McpToken { | ||
| /** | ||
| * Token id | ||
| */ | ||
| id: number; | ||
|
|
||
| /** | ||
| * Last characters of the token, used to tell tokens apart | ||
| */ | ||
| preview: string; | ||
|
|
||
| /** | ||
| * What MCP client can do with notes of the token owner | ||
| */ | ||
| permission: McpTokenPermission; | ||
|
|
||
| /** | ||
| * Label set by user, e.g. "Claude Code on laptop" | ||
| */ | ||
| label: string; | ||
|
|
||
| /** | ||
| * Last time token was used to call MCP tool | ||
| */ | ||
| lastUsedAt: string | null; | ||
|
|
||
| /** | ||
| * How many times token was used to call MCP tools | ||
| */ | ||
| requestCount: number; | ||
|
|
||
| /** | ||
| * When token was created | ||
| */ | ||
| createdAt: string; | ||
| } | ||
|
|
||
| /** | ||
| * Token returned right after creation. Plain token is shown only once | ||
| */ | ||
| export interface CreatedMcpToken { | ||
| /** | ||
| * Plain token to paste into MCP client config | ||
| */ | ||
| token: string; | ||
|
|
||
| /** | ||
| * Created token record | ||
| */ | ||
| item: McpToken; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { CreatedMcpToken, McpToken, McpTokenPermission } from './entities/McpToken'; | ||
|
|
||
| /** | ||
| * Interface of the user settings repository | ||
| */ | ||
| export default interface UserSettingsRepositoryInterface { | ||
| /** | ||
| * Loads all MCP tokens of the current user | ||
| */ | ||
| getMcpTokens(): Promise<McpToken[]>; | ||
|
|
||
| /** | ||
| * Creates new MCP token | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| */ | ||
| createMcpToken(label: string, permission: McpTokenPermission): Promise<CreatedMcpToken>; | ||
|
|
||
| /** | ||
| * Revokes MCP token | ||
| * @param id - token id | ||
| */ | ||
| revokeMcpToken(id: McpToken['id']): Promise<void>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { CreatedMcpToken, McpToken, McpTokenPermission } from './entities/McpToken'; | ||
| import type UserSettingsRepository from './userSettings.repository.interface'; | ||
|
|
||
| /** | ||
| * User settings service class, used for logic handling of the data, | ||
| * Also used for data delivery from repository to application service | ||
| */ | ||
| export default class UserSettingsService { | ||
| /** | ||
| * User settings repository instance | ||
| */ | ||
| private readonly userSettingsRepository: UserSettingsRepository; | ||
|
|
||
| constructor(userSettingsRepository: UserSettingsRepository) { | ||
| this.userSettingsRepository = userSettingsRepository; | ||
| } | ||
|
|
||
| /** | ||
| * Loads all MCP tokens of the current user | ||
| */ | ||
| public async getMcpTokens(): Promise<McpToken[]> { | ||
| return await this.userSettingsRepository.getMcpTokens(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates new MCP token | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| */ | ||
| public async createMcpToken(label: string, permission: McpTokenPermission): Promise<CreatedMcpToken> { | ||
| return await this.userSettingsRepository.createMcpToken(label, permission); | ||
| } | ||
|
|
||
| /** | ||
| * Revokes MCP token | ||
| * @param id - token id | ||
| */ | ||
| public async revokeMcpToken(id: McpToken['id']): Promise<void> { | ||
| await this.userSettingsRepository.revokeMcpToken(id); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import type UserSettingsRepositoryInterface from '@/domain/userSettings.repository.interface'; | ||
| import type NotesApiTransport from './transport/notes-api'; | ||
| import type { CreatedMcpToken, McpToken, McpTokenPermission } from '@/domain/entities/McpToken'; | ||
|
|
||
| /** | ||
| * User settings repository class used for data delivery from transport to service | ||
| */ | ||
| export default class UserSettingsRepository implements UserSettingsRepositoryInterface { | ||
| /** | ||
| * Notes api transport instance | ||
| */ | ||
| private readonly transport: NotesApiTransport; | ||
|
|
||
| constructor(notesApiTransport: NotesApiTransport) { | ||
| this.transport = notesApiTransport; | ||
| } | ||
|
|
||
| /** | ||
| * Loads all MCP tokens of the current user | ||
| */ | ||
| public async getMcpTokens(): Promise<McpToken[]> { | ||
| const response = await this.transport.get<{ items: McpToken[] }>('/user/mcp-tokens'); | ||
|
|
||
| return response.items; | ||
| } | ||
|
|
||
| /** | ||
| * Creates new MCP token | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| */ | ||
| public async createMcpToken(label: string, permission: McpTokenPermission): Promise<CreatedMcpToken> { | ||
| return await this.transport.post<CreatedMcpToken>({ | ||
| endpoint: '/user/mcp-tokens', | ||
| data: { | ||
| label, | ||
| permission, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Revokes MCP token | ||
| * @param id - token id | ||
| */ | ||
| public async revokeMcpToken(id: McpToken['id']): Promise<void> { | ||
| await this.transport.delete<{ isDeleted: boolean }>(`/user/mcp-tokens/${id}`); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.