Skip to main content
Glama
efremidze

swift-patterns-mcp

get_swift_pattern

Retrieve Swift and SwiftUI coding patterns from trusted sources like Sundell and SwiftLee for conceptual guidance and practical examples.

Instructions

Get Swift/SwiftUI reference patterns from curated free sources (Sundell, van der Lee, Nil Coalescing, Point-Free). Best for conceptual guidance and free-source examples.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
topicYesTopic to search (e.g., 'swiftui', 'testing', 'async-await', 'performance')
sourceNoSpecific source to search (default: all free sources)
minQualityNoMinimum quality score 0-100 (default: 60)

Implementation Reference

  • The `getSwiftPatternHandler` function implements the `get_swift_pattern` tool logic, which validates arguments, performs a cached search across sources, and formats the results.
    export const getSwiftPatternHandler: ToolHandler = async (args, context) => {
      const topic = validateRequiredString(args, 'topic', `Usage: get_swift_pattern({ topic: "swiftui" })
    
    Example topics:
    - swiftui, concurrency, testing, networking
    - performance, architecture, protocols
    - async-await, combine, coredata`);
      if (isValidationError(topic)) return topic;
    
      const sourceValidated = validateOptionalString(args, 'source');
      if (isValidationError(sourceValidated)) return sourceValidated;
      const source = sourceValidated || "all";
    
      const minQualityValidated = validateOptionalNumber(args, 'minQuality');
      if (isValidationError(minQualityValidated)) return minQualityValidated;
      const minQuality = minQualityValidated || 65;
      const wantsCode = detectCodeIntent(args, topic);
    
      if (source !== 'all' && !FREE_SOURCE_NAMES.includes(source as FreeSourceName)) {
        const patreonCreator = CREATORS.find(c => c.id.toLowerCase() === source.toLowerCase());
    
        if (patreonCreator) {
          return createTextResponse(`"${patreonCreator.name}" is a Patreon creator, not a free source.
    
    Use get_patreon_patterns to search Patreon content:
    get_patreon_patterns({ topic: "${topic}" })`);
        }
    
        return createTextResponse(`"${source}" isn't a recognized source.
    
    Available free sources: ${FREE_SOURCE_NAMES.join(', ')}
    Patreon creators: ${CREATORS.map(c => c.id).join(', ')}
    
    For free sources, use:
    get_swift_pattern({ topic: "${topic}", source: "sundell" })
    
    For Patreon creators, use:
    get_patreon_patterns({ topic: "${topic}" })`);
      }
    
      // Build intent key for caching
      const intentKey: IntentKey = {
        tool: 'get_swift_pattern_hybrid_v3',
        query: topic,
        minQuality,
        sources: getSourceNames(source as FreeSourceName | 'all'),
      };
    
      const { results } = await cachedSearch({
        intentKey,
        sourceManager: context.sourceManager,
        fetcher: async () => {
          const searchSource = source as FreeSourceName | 'all';
          const profile = buildQueryProfile(topic);
          const [strictResults, broadResults] = await Promise.all([
            searchMultipleSources(topic, searchSource),
            runBroadSearch(topic, searchSource, profile),
          ]);
          return mergeAndRankPatterns(topic, minQuality, strictResults, broadResults);
        },
      });
    
      if (results.length === 0) {
        return createMarkdownResponse(
          `Swift Patterns: ${topic}`,
          `No patterns found for "${topic}" with quality ≥ ${minQuality}.`,
          `Try:
    - Broader search terms
    - Lower minQuality
    - Different topic
    - search_swift_content({ query: "${topic}" }) for broader discovery`,
          'Available sources: Swift by Sundell, Antoine van der Lee, Nil Coalescing, Point-Free',
          context.sourceManager.isSourceConfigured('patreon')
            ? `💡 For creator-specific/tutorial content, use get_patreon_patterns({ topic: "${topic}" }).`
            : undefined,
        );
      }
    
      // Format using shared utility
      const formatted = formatTopicPatterns(results, topic, {
        ...COMMON_FORMAT_OPTIONS,
        includeCode: wantsCode,
      });
    
      return createTextResponse(formatted);
    };

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/efremidze/swift-mcp'

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