Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.desktop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tableau Desktop Authoring MCP
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"scripts": {
"build": "tsx src/scripts/build.ts",
"build:desktop": "tsx src/scripts/build.ts --variant desktop",
"build:dev": "tsx src/scripts/build.ts --dev",
"build:docker": "docker build -t tableau-mcp .",
":build:mcpb": "npx -y @anthropic-ai/mcpb pack . tableau-mcp.mcpb",
Expand Down
38 changes: 38 additions & 0 deletions src/index.desktop.ts
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);
});
72 changes: 72 additions & 0 deletions src/scripts/prepareVariantPackage.ts
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',
Copy link
Copy Markdown
Contributor

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 produces

Should this be derived from the same source of truth as the build script so they can’t drift?

Copy link
Copy Markdown
Collaborator Author

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.

},
},
} 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');
}
2 changes: 1 addition & 1 deletion src/scripts/variants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const variants = ['default'] as const;
export const variants = ['default', 'desktop'] as const;
export type Variant = (typeof variants)[number];
export function isVariant(value: unknown): value is Variant {
return variants.some((variant) => variant === value);
Expand Down
3 changes: 2 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boundary Q here: do we want server.ts branching on BUILD_VARIANT at all?

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}`;

Expand Down