Skip to main content
Glama

Generate a new token for a specific database

generate_database_token

Generate a new authentication token for any Turso database, choosing between full-access or read-only permissions.

Instructions

Generate a new token for a specific database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesName of the database to generate a token for
permissionNoPermission level for the token

Implementation Reference

  • Handler registration for the 'generate_database_token' MCP tool - defines the tool name, description, schema, and the async handler function that calls organization_client.generate_database_token
    server.tool(
    	{
    		name: 'generate_database_token',
    		description: 'Generate a new token for a specific database',
    		schema: GenerateDatabaseTokenSchema,
    	},
    	async ({ database, permission = 'full-access' }) => {
    		try {
    			const jwt = await organization_client.generate_database_token(
    				database,
    				permission,
    			);
    			return create_tool_response({
    				success: true,
    				database,
    				token: { jwt, permission, database },
    				message: `Token generated successfully for database '${database}' with '${permission}' permissions`,
    			});
    		} catch (error) {
    			return create_tool_error_response(error);
    		}
    	},
  • Zod schema for input validation of generate_database_token - requires 'database' (string) and optional 'permission' enum (full-access or read-only)
    const GenerateDatabaseTokenSchema = z.object({
    	database: z.string().describe('Name of the database to generate a token for'),
    	permission: z.enum(['full-access', 'read-only']).optional().describe('Permission level for the token'),
    });
  • Registration of the generate_database_token tool on the MCP server via server.tool()
    server.tool(
    	{
    		name: 'generate_database_token',
    		description: 'Generate a new token for a specific database',
    		schema: GenerateDatabaseTokenSchema,
    	},
  • Wrapper function in organization client that re-exports the token-manager's generate_database_token to avoid circular imports
    export async function generate_database_token(
    	database_name: string,
    	permission: 'full-access' | 'read-only' = 'full-access',
    ): Promise<string> {
    	// Import here to avoid circular dependencies
    	const { generate_database_token: generate_token } = await import(
    		'./token-manager.js'
    	);
    	return generate_token(database_name, permission);
    }
  • Core implementation - makes a POST request to the Turso API to generate a database auth token with specified permission and expiration
    export async function generate_database_token(
    	database_name: string,
    	permission: 'full-access' | 'read-only' = 'full-access',
    ): Promise<string> {
    	const config = get_config();
    	const url = `https://api.turso.tech/v1/organizations/${config.TURSO_ORGANIZATION}/databases/${database_name}/auth/tokens`;
    
    	try {
    		const response = await fetch(url, {
    			method: 'POST',
    			headers: {
    				Authorization: `Bearer ${config.TURSO_API_TOKEN}`,
    				'Content-Type': 'application/json',
    			},
    			body: JSON.stringify({
    				expiration: config.TOKEN_EXPIRATION,
    				permission,
    			}),
    		});
    
    		if (!response.ok) {
    			const errorData = await response.json().catch(() => ({}));
    			const errorMessage = errorData.error || response.statusText;
    			throw new TursoApiError(
    				`Failed to generate token for database ${database_name}: ${errorMessage}`,
    				response.status,
    			);
    		}
    
    		const data = await response.json();
    		return data.jwt;
    	} catch (error) {
    		if (error instanceof TursoApiError) {
    			throw error;
    		}
    		throw new TursoApiError(
    			`Failed to generate token for database ${database_name}: ${
    				(error as Error).message
    			}`,
    			500,
    		);
    	}
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states that a token is generated. It fails to disclose behavioral traits such as whether the token is immediately valid, if it overrides existing tokens, or if special permissions are required. The lack of side-effect information is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, making it concise, but it is too brief and lacks substantive content. While not verbose, it sacrifices clarity for brevity. A slightly longer description with key details would improve understandability without being wasteful.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (2 parameters, no nested objects) and absence of annotations or output schema, the description is incomplete. It does not mention what the tool returns (e.g., the token string), any side effects, or potential errors. The description alone is insufficient for an agent to use the tool safely.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema covers 100% of parameters with descriptions, so the description adds minimal extra meaning. The baseline is 3. The description does not elaborate on the 'permission' enum values or the format of the 'database' name, but the schema is already clear.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tautological: description restates name/title.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives, prerequisites, or situations where it should not be used. The description lacks any context about the tool's intended use case or limitations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/spences10/mcp-turso-cloud'

If you have feedback or need assistance with the MCP directory API, please join our Discord server