-
Notifications
You must be signed in to change notification settings - Fork 93
@W-22188550: Add "desktop" build variant #330
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
base: anyoung/desktop-tool-context
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Tableau Desktop Authoring MCP |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; | ||
| import dotenv from 'dotenv'; | ||
|
|
||
| import { getDesktopConfig } from './config.desktop.js'; | ||
| import { FileLogger, setFileLogger } from './logging/fileLogger.js'; | ||
| import { writeToStderr } from './logging/logger.js'; | ||
| import { isNotificationLevel, notifier, setNotificationLevel } from './logging/notification.js'; | ||
| import { DesktopMcpServer } from './server.desktop.js'; | ||
| import { getExceptionMessage } from './utils/getExceptionMessage.js'; | ||
|
|
||
| async function startServer(): Promise<void> { | ||
| dotenv.config(); | ||
| const config = getDesktopConfig(); | ||
|
|
||
| const logLevel = isNotificationLevel(config.defaultLogLevel) ? config.defaultLogLevel : 'debug'; | ||
| if (config.loggers.has('fileLogger')) { | ||
| setFileLogger(new FileLogger({ logDirectory: config.fileLoggerDirectory })); | ||
| } | ||
|
|
||
| if (config.transport !== 'stdio') { | ||
| throw new Error('Transport must be stdio for Desktop server'); | ||
| } | ||
|
|
||
| const server = new DesktopMcpServer(); | ||
| await server.registerTools(); | ||
| server.registerRequestHandlers(); | ||
|
|
||
| const transport = new StdioServerTransport(); | ||
| await server.mcpServer.connect(transport); | ||
|
|
||
| setNotificationLevel(server, logLevel); | ||
| notifier.info(server, `${server.name} v${server.version} running on stdio`); | ||
| } | ||
|
|
||
| startServer().catch((error) => { | ||
| writeToStderr(`Fatal error when starting the server: ${getExceptionMessage(error)}`); | ||
| process.exit(1); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { existsSync } from 'fs'; | ||
| import { copyFile, readFile, writeFile } from 'fs/promises'; | ||
| import { dirname, join } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| import { z } from 'zod'; | ||
|
|
||
| import { isVariant, Variant, variants } from './variants'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const repoRoot = join(__dirname, '..', '..'); | ||
| const packageJsonPath = join(repoRoot, 'package.json'); | ||
|
|
||
| const variant = process.argv.includes('--variant') | ||
| ? process.argv[process.argv.indexOf('--variant') + 1] | ||
| : 'default'; | ||
|
|
||
| if (!isVariant(variant)) { | ||
| throw new Error(`Invalid build variant: ${variant}. Expected one of: ${variants.join(', ')}`); | ||
| } | ||
|
|
||
| if (variant === 'default') { | ||
| throw new Error('The default variant needs no preparation'); | ||
| } | ||
|
|
||
| type PackageVariant = Exclude<Variant, 'default'>; | ||
| const variantPackageJsonOverrides = { | ||
| desktop: { | ||
| name: '@tableau/desktop-mcp-server', | ||
| description: | ||
| 'MCP server for Tableau Desktop Agent API - enables AI agents to interact with Tableau workbooks', | ||
| bin: { | ||
| 'tableau-desktop-mcp-server': './build/index-desktop.js', | ||
| }, | ||
| exports: { | ||
| '.': './build/index-desktop.js', | ||
| }, | ||
| }, | ||
| } satisfies Record<PackageVariant, Partial<PackageJson>>; | ||
|
|
||
| const packageJsonSchema = z | ||
| .object({ | ||
| name: z.string(), | ||
| description: z.string(), | ||
| bin: z.record(z.string()), | ||
| exports: z.record(z.string()), | ||
| }) | ||
| .passthrough(); | ||
|
|
||
| type PackageJson = z.infer<typeof packageJsonSchema>; | ||
|
|
||
| (async () => { | ||
| const overrides = variantPackageJsonOverrides[variant]; | ||
| const packageJson = { ...(await readPackageJson()), ...overrides }; | ||
| await writePackageJson(packageJson); | ||
|
|
||
| if (existsSync(join(repoRoot, `README.${variant}.md`))) { | ||
| await copyFile(join(repoRoot, `README.${variant}.md`), join(repoRoot, 'README.md')); | ||
| } | ||
| })().catch((error: unknown) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); | ||
|
|
||
| async function readPackageJson(): Promise<PackageJson> { | ||
| const raw = await readFile(packageJsonPath, 'utf-8'); | ||
| const parsed = JSON.parse(raw); | ||
| return packageJsonSchema.parse(parsed); | ||
| } | ||
|
|
||
| async function writePackageJson(data: PackageJson): Promise<void> { | ||
| await writeFile(packageJsonPath, JSON.stringify(data, null, 2) + '\n', 'utf-8'); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,8 @@ import pkg from '../package.json'; | |
| import { setNotificationLevel } from './logging/notification.js'; | ||
| import { TableauAuthInfo } from './server/oauth/schemas.js'; | ||
|
|
||
| export const serverName = 'tableau-mcp'; | ||
| export const serverName = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Boundary Q here: do we want The rest of this stack is trying to keep variant-specific behavior in the entry/variant layer, and putting the conditional in shared code feels like an escape hatch that could spread over time Should the variant-specific server name come from the entry point or concrete server instead? |
||
| import.meta.env.BUILD_VARIANT === 'desktop' ? 'tableau-desktop-mcp' : 'tableau-mcp'; | ||
| export const serverVersion = pkg.version; | ||
| export const userAgent = `${serverName}/${serverVersion}`; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package wiring is pointing at the wrong file name here, yeah?
The desktop build output is
./build/index.desktop.js, but these package entries use./build/index-desktop.js, so the published package would resolve to a file the build never producesShould this be derived from the same source of truth as the build script so they can’t drift?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good catch. Not sure where that dash came from.